Skip to contentSkip to conversation

DVFS for IO devices on sdm845 and sc7180

PATCH Applied Rajendra Nayak 6 participants 41 messages Apr 8, 2020 – Apr 16, 2020

Subsystems (15)

v1 of 6 Applied Latest is v6 →

lore
Share & tools
lore
#0 lore raw

cover DVFS for IO devices on sdm845 and sc7180

We have had support added in the OPP core for a while now to support DVFS for IO devices, and this series uses that infrastructure to add DVFS support for various IO devices in sdm845 and sc7180 SoCs.

Rajendra Nayak (21):
opp: Manage empty OPP tables with clk handle
tty: serial: qcom_geni_serial: Use OPP API to set clk/perf state
spi: spi-geni-qcom: Use OPP API to set clk/perf state
arm64: dts: sdm845: Add OPP table for all qup devices
arm64: dts: sc7180: Add OPP table for all qup devices
scsi: ufs: Add support to manage multiple power domains in
ufshcd-pltfrm
scsi: ufs: Add support for specifying OPP tables in DT
arm64: dts: sdm845: Add ufs opps and power-domains drm/msm/dpu: Use OPP API to set clk/perf state drm/msm: dsi: Use OPP API to set clk/perf state
arm64: dts: sdm845: Add DSI and MDP OPP tables and power-domains
arm64: dts: sc7180: Add DSI and MDP OPP tables and power-domains
mmc: sdhci-msm: Use OPP API to set clk/perf state
arm64: dts: sdm845: Add sdhc opps and power-domains
arm64: dts: sc7180: Add sdhc opps and power-domains
media: venus: core: Add support for opp tables/perf voting
arm64: dts: sdm845: Add OPP tables and power-domains for venus
arm64: dts: sc7180: Add OPP tables and power-domains for venus
spi: spi-qcom-qspi: Use OPP API to set clk/perf state
arm64: dts: sdm845: Add qspi opps and power-domains
arm64: dts: sc7180: Add qspi opps and power-domains

 arch/arm64/boot/dts/qcom/sc7180.dtsi           | 199 ++++++++++++++++-
 arch/arm64/boot/dts/qcom/sdm845.dtsi           | 287 ++++++++++++++++++++++++-
 drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c  |   3 +-
 drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c        |   6 +
 drivers/gpu/drm/msm/dsi/dsi.h                  |   2 +
 drivers/gpu/drm/msm/dsi/dsi_cfg.c              |   4 +-
 drivers/gpu/drm/msm/dsi/dsi_host.c             |  48 +++++
 drivers/media/platform/qcom/venus/core.c       |  16 ++
 drivers/media/platform/qcom/venus/core.h       |   4 +
 drivers/media/platform/qcom/venus/pm_helpers.c |  37 +++-
 drivers/mmc/host/sdhci-msm.c                   |  20 +-
 drivers/opp/core.c                             |  14 ++
 drivers/scsi/ufs/ufshcd-pltfrm.c               |  58 ++++-
 drivers/scsi/ufs/ufshcd.c                      |  17 +-
 drivers/scsi/ufs/ufshcd.h                      |   3 +
 drivers/spi/spi-geni-qcom.c                    |  14 +-
 drivers/spi/spi-qcom-qspi.c                    |  10 +-
 drivers/tty/serial/qcom_geni_serial.c          |  20 +-
 include/linux/qcom-geni-se.h                   |   2 +
 19 files changed, 735 insertions(+), 29 deletions(-)
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#1 lore raw

PATCH 1/21 opp: Manage empty OPP tables with clk handle

With OPP core now supporting DVFS for IO devices, we have instances of IO devices (same IP block) which require an OPP on some platforms/SoCs while just needing to scale the clock on some others.

In order to avoid conditional code in every driver which supports such devices (to check for availability of OPPs and then deciding to do either dev_pm_opp_set_rate() or clk_set_rate()) add support to manage empty OPP tables with a clk handle.

This makes dev_pm_opp_set_rate() equivalent of a clk_set_rate() for devices with just a clk and no OPPs specified, and makes dev_pm_opp_set_rate(0) bail out without throwing an error.

---
 drivers/opp/core.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/opp/core.c +14 -0
index ba43e6a..e4f01e7 100644
@@ -819,6 +819,8 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
 	if (unlikely(!target_freq)) {
 		if (opp_table->required_opp_tables) {
 			ret = _set_required_opps(dev, opp_table, NULL);
+		} else if (!_get_opp_count(opp_table)) {
+			return 0;
 		} else {
 			dev_err(dev, "target frequency can't be 0\n");
 			ret = -EINVAL;
@@ -849,6 +851,18 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
 		goto put_opp_table;
 	}
 
+	/*
+	 * For IO devices which require an OPP on some platforms/SoCs
+	 * while just needing to scale the clock on some others
+	 * we look for empty OPP tables with just a clock handle and
+	 * scale only the clk. This makes dev_pm_opp_set_rate()
+	 * equivalent to a clk_set_rate()
+	 */
+	if (!_get_opp_count(opp_table)) {
+		ret = _generic_set_opp_clk_only(dev, clk, freq);
+		goto put_opp_table;
+	}
+
 	temp_freq = old_freq;
 	old_opp = _find_freq_ceil(opp_table, &temp_freq);
 	if (IS_ERR(old_opp)) {
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#6 lore raw

PATCH 2/21 tty: serial: qcom_geni_serial: Use OPP API to set clk/perf state

In reply to Rajendra Nayak

geni serial needs to express a perforamnce state requirement on CX 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.

---
 drivers/tty/serial/qcom_geni_serial.c | 20 +++++++++++++++-----
 include/linux/qcom-geni-se.h          |  2 ++
 2 files changed, 17 insertions(+), 5 deletions(-)
drivers/tty/serial/qcom_geni_serial.c +15 -5
index 6119090..754eaf6 100644
@@ -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>
@@ -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;
 
@@ -1198,8 +1199,10 @@ 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) {
+		dev_pm_opp_set_rate(uport->dev, 0);
 		geni_se_resources_off(&port->se);
+	}
 }
 
 static const struct uart_ops qcom_geni_console_pops = {
@@ -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);
+	return ret;
 }
 
 static int qcom_geni_serial_remove(struct platform_device *pdev)
@@ -1361,6 +1370,7 @@ 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;
 
+	dev_pm_opp_of_remove_table(&pdev->dev);
 	dev_pm_clear_wake_irq(&pdev->dev);
 	device_init_wakeup(&pdev->dev, false);
 	uart_remove_one_port(drv, &port->uport);
include/linux/qcom-geni-se.h +2 -0
index dd46494..737e713 100644
@@ -24,6 +24,7 @@ enum geni_se_protocol_type {
 
 struct geni_wrapper;
 struct clk;
+struct opp_table;
 
 /**
  * struct geni_se - GENI Serial Engine
@@ -39,6 +40,7 @@ struct geni_se {
 	struct device *dev;
 	struct geni_wrapper *wrapper;
 	struct clk *clk;
+	struct opp_table *opp;
 	unsigned int num_clk_levels;
 	unsigned long *clk_perf_tbl;
 };
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#15 lore raw

PATCH 3/21 spi: spi-geni-qcom: Use OPP API to set clk/perf state

In reply to Rajendra Nayak

geni spi needs to express a perforamnce state requirement on CX 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.

---
 drivers/spi/spi-geni-qcom.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/spi/spi-geni-qcom.c +11 -3
index c397242..ce387dc 100644
@@ -7,6 +7,7 @@
 #include <linux/log2.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/pm_opp.h>
 #include <linux/pm_runtime.h>
 #include <linux/qcom-geni-se.h>
 #include <linux/spi/spi.h>
@@ -95,7 +96,6 @@ static int get_spi_clk_cfg(unsigned int speed_hz,
 {
 	unsigned long sclk_freq;
 	unsigned int actual_hz;
-	struct geni_se *se = &mas->se;
 	int ret;
 
 	ret = geni_se_clk_freq_match(&mas->se,
@@ -112,9 +112,9 @@ static int get_spi_clk_cfg(unsigned int speed_hz,
 
 	dev_dbg(mas->dev, "req %u=>%u sclk %lu, idx %d, div %d\n", speed_hz,
 				actual_hz, sclk_freq, *clk_idx, *clk_div);
-	ret = clk_set_rate(se->clk, sclk_freq);
+	ret = dev_pm_opp_set_rate(mas->dev, sclk_freq);
 	if (ret)
-		dev_err(mas->dev, "clk_set_rate failed %d\n", ret);
+		dev_err(mas->dev, "dev_pm_opp_set_rate failed %d\n", ret);
 	return ret;
 }
 
@@ -553,6 +553,7 @@ static int spi_geni_probe(struct platform_device *pdev)
 	if (!spi)
 		return -ENOMEM;
 
+
 	platform_set_drvdata(pdev, spi);
 	mas = spi_master_get_devdata(spi);
 	mas->irq = irq;
@@ -561,6 +562,8 @@ static int spi_geni_probe(struct platform_device *pdev)
 	mas->se.wrapper = dev_get_drvdata(dev->parent);
 	mas->se.base = base;
 	mas->se.clk = clk;
+	mas->se.opp = dev_pm_opp_set_clkname(&pdev->dev, "se");
+	dev_pm_opp_of_add_table(&pdev->dev);
 
 	spi->bus_num = -1;
 	spi->dev.of_node = dev->of_node;
@@ -596,6 +599,7 @@ static int spi_geni_probe(struct platform_device *pdev)
 spi_geni_probe_runtime_disable:
 	pm_runtime_disable(dev);
 	spi_master_put(spi);
+	dev_pm_opp_of_remove_table(&pdev->dev);
 	return ret;
 }
 
@@ -604,6 +608,7 @@ static int spi_geni_remove(struct platform_device *pdev)
 	struct spi_master *spi = platform_get_drvdata(pdev);
 	struct spi_geni_master *mas = spi_master_get_devdata(spi);
 
+	dev_pm_opp_of_remove_table(&pdev->dev);
 	/* Unregister _before_ disabling pm_runtime() so we stop transfers */
 	spi_unregister_master(spi);
 
@@ -617,6 +622,9 @@ static int __maybe_unused spi_geni_runtime_suspend(struct device *dev)
 	struct spi_master *spi = dev_get_drvdata(dev);
 	struct spi_geni_master *mas = spi_master_get_devdata(spi);
 
+	/* Drop the performance state vote */
+	dev_pm_opp_set_rate(dev, 0);
+
 	return geni_se_resources_off(&mas->se);
 }
 
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#19 lore raw

PATCH 5/21 arm64: dts: sc7180: Add OPP table for all qup devices

In reply to Rajendra Nayak

qup has a requirement to vote on the performance state of the CX domain in sc7180 devices. Add OPP tables for these and also add power-domains property for all qup instances.

---
 arch/arm64/boot/dts/qcom/sc7180.dtsi | 79 ++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)
arch/arm64/boot/dts/qcom/sc7180.dtsi +79 -0
index 998f101..efba600 100644
@@ -417,6 +417,25 @@
 			status = "disabled";
 		};
 
+		qup_opp_table: qup-opp-table {
+			compatible = "operating-points-v2";
+
+			opp-75000000 {
+				opp-hz = /bits/ 64 <75000000>;
+				required-opps = <&rpmhpd_opp_low_svs>;
+			};
+
+			opp-100000000 {
+				opp-hz = /bits/ 64 <100000000>;
+				required-opps = <&rpmhpd_opp_svs>;
+			};
+
+			opp-128000000 {
+				opp-hz = /bits/ 64 <128000000>;
+				required-opps = <&rpmhpd_opp_nom>;
+			};
+		};
+
 		qupv3_id_0: geniqup@8c0000 {
 			compatible = "qcom,geni-se-qup";
 			reg = <0 0x008c0000 0 0x6000>;
@@ -452,6 +471,8 @@
 				interrupts = <GIC_SPI 601 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -463,6 +484,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart0_default>;
 				interrupts = <GIC_SPI 601 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -476,6 +499,8 @@
 				interrupts = <GIC_SPI 602 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -489,6 +514,8 @@
 				interrupts = <GIC_SPI 602 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -500,6 +527,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart1_default>;
 				interrupts = <GIC_SPI 602 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -513,6 +542,8 @@
 				interrupts = <GIC_SPI 603 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -524,6 +555,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart2_default>;
 				interrupts = <GIC_SPI 603 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -537,6 +570,8 @@
 				interrupts = <GIC_SPI 604 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -550,6 +585,8 @@
 				interrupts = <GIC_SPI 604 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -561,6 +598,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart3_default>;
 				interrupts = <GIC_SPI 604 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -574,6 +613,8 @@
 				interrupts = <GIC_SPI 605 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -585,6 +626,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart4_default>;
 				interrupts = <GIC_SPI 605 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -598,6 +641,8 @@
 				interrupts = <GIC_SPI 606 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -611,6 +656,8 @@
 				interrupts = <GIC_SPI 606 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -622,6 +669,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart5_default>;
 				interrupts = <GIC_SPI 606 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 		};
@@ -661,6 +710,8 @@
 				interrupts = <GIC_SPI 353 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -672,6 +723,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart6_default>;
 				interrupts = <GIC_SPI 353 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -685,6 +738,8 @@
 				interrupts = <GIC_SPI 354 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -696,6 +751,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart7_default>;
 				interrupts = <GIC_SPI 354 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -709,6 +766,8 @@
 				interrupts = <GIC_SPI 355 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -722,6 +781,8 @@
 				interrupts = <GIC_SPI 355 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -733,6 +794,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart8_default>;
 				interrupts = <GIC_SPI 355 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -746,6 +809,8 @@
 				interrupts = <GIC_SPI 356 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -757,6 +822,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart9_default>;
 				interrupts = <GIC_SPI 356 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -770,6 +837,8 @@
 				interrupts = <GIC_SPI 357 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -783,6 +852,8 @@
 				interrupts = <GIC_SPI 357 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -794,6 +865,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart10_default>;
 				interrupts = <GIC_SPI 357 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -807,6 +880,8 @@
 				interrupts = <GIC_SPI 358 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -820,6 +895,8 @@
 				interrupts = <GIC_SPI 358 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -831,6 +908,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart11_default>;
 				interrupts = <GIC_SPI 358 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SC7180_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 		};
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#18 lore raw

PATCH 4/21 arm64: dts: sdm845: Add OPP table for all qup devices

In reply to Rajendra Nayak

qup has a requirement to vote on the performance state of the CX domain in sdm845 devices. Add OPP tables for these and also add power-domains property for all qup instances.

---
 arch/arm64/boot/dts/qcom/sdm845.dtsi | 115 +++++++++++++++++++++++++++++++++++
 1 file changed, 115 insertions(+)
arch/arm64/boot/dts/qcom/sdm845.dtsi +115 -0
index 8f926b5..36b9fb1 100644
@@ -804,6 +804,25 @@
 			clock-names = "core";
 		};
 
+		qup_opp_table: qup-opp-table {
+			compatible = "operating-points-v2";
+
+			opp-19200000 {
+				opp-hz = /bits/ 64 <19200000>;
+				required-opps = <&rpmhpd_opp_min_svs>;
+			};
+
+			opp-75000000 {
+				opp-hz = /bits/ 64 <75000000>;
+				required-opps = <&rpmhpd_opp_low_svs>;
+			};
+
+			opp-100000000 {
+				opp-hz = /bits/ 64 <100000000>;
+				required-opps = <&rpmhpd_opp_svs>;
+			};
+		};
+
 		qupv3_id_0: geniqup@8c0000 {
 			compatible = "qcom,geni-se-qup";
 			reg = <0 0x008c0000 0 0x6000>;
@@ -825,6 +844,8 @@
 				interrupts = <GIC_SPI 601 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -838,6 +859,8 @@
 				interrupts = <GIC_SPI 601 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -849,6 +872,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart0_default>;
 				interrupts = <GIC_SPI 601 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -862,6 +887,8 @@
 				interrupts = <GIC_SPI 602 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -875,6 +902,8 @@
 				interrupts = <GIC_SPI 602 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -886,6 +915,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart1_default>;
 				interrupts = <GIC_SPI 602 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -899,6 +930,8 @@
 				interrupts = <GIC_SPI 603 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -912,6 +945,8 @@
 				interrupts = <GIC_SPI 603 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -923,6 +958,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart2_default>;
 				interrupts = <GIC_SPI 603 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -936,6 +973,8 @@
 				interrupts = <GIC_SPI 604 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -949,6 +988,8 @@
 				interrupts = <GIC_SPI 604 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -960,6 +1001,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart3_default>;
 				interrupts = <GIC_SPI 604 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -973,6 +1016,8 @@
 				interrupts = <GIC_SPI 605 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -986,6 +1031,8 @@
 				interrupts = <GIC_SPI 605 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -997,6 +1044,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart4_default>;
 				interrupts = <GIC_SPI 605 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1010,6 +1059,8 @@
 				interrupts = <GIC_SPI 606 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1023,6 +1074,8 @@
 				interrupts = <GIC_SPI 606 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1034,6 +1087,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart5_default>;
 				interrupts = <GIC_SPI 606 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1047,6 +1102,8 @@
 				interrupts = <GIC_SPI 607 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1060,6 +1117,8 @@
 				interrupts = <GIC_SPI 607 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1071,6 +1130,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart6_default>;
 				interrupts = <GIC_SPI 607 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1084,6 +1145,8 @@
 				interrupts = <GIC_SPI 608 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1097,6 +1160,8 @@
 				interrupts = <GIC_SPI 608 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1108,6 +1173,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart7_default>;
 				interrupts = <GIC_SPI 608 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 		};
@@ -1133,6 +1200,8 @@
 				interrupts = <GIC_SPI 353 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1146,6 +1215,8 @@
 				interrupts = <GIC_SPI 353 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1157,6 +1228,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart8_default>;
 				interrupts = <GIC_SPI 353 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1170,6 +1243,8 @@
 				interrupts = <GIC_SPI 354 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1183,6 +1258,8 @@
 				interrupts = <GIC_SPI 354 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1194,6 +1271,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart9_default>;
 				interrupts = <GIC_SPI 354 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1207,6 +1286,8 @@
 				interrupts = <GIC_SPI 355 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1220,6 +1301,8 @@
 				interrupts = <GIC_SPI 355 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1231,6 +1314,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart10_default>;
 				interrupts = <GIC_SPI 355 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1244,6 +1329,8 @@
 				interrupts = <GIC_SPI 356 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1257,6 +1344,8 @@
 				interrupts = <GIC_SPI 356 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1268,6 +1357,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart11_default>;
 				interrupts = <GIC_SPI 356 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1281,6 +1372,8 @@
 				interrupts = <GIC_SPI 357 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1294,6 +1387,8 @@
 				interrupts = <GIC_SPI 357 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1305,6 +1400,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart12_default>;
 				interrupts = <GIC_SPI 357 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1318,6 +1415,8 @@
 				interrupts = <GIC_SPI 358 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1331,6 +1430,8 @@
 				interrupts = <GIC_SPI 358 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1342,6 +1443,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart13_default>;
 				interrupts = <GIC_SPI 358 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1355,6 +1458,8 @@
 				interrupts = <GIC_SPI 359 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1368,6 +1473,8 @@
 				interrupts = <GIC_SPI 359 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1379,6 +1486,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart14_default>;
 				interrupts = <GIC_SPI 359 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1392,6 +1501,8 @@
 				interrupts = <GIC_SPI 360 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1405,6 +1516,8 @@
 				interrupts = <GIC_SPI 360 IRQ_TYPE_LEVEL_HIGH>;
 				#address-cells = <1>;
 				#size-cells = <0>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 
@@ -1416,6 +1529,8 @@
 				pinctrl-names = "default";
 				pinctrl-0 = <&qup_uart15_default>;
 				interrupts = <GIC_SPI 360 IRQ_TYPE_LEVEL_HIGH>;
+				power-domains = <&rpmhpd SDM845_CX>;
+				operating-points-v2 = <&qup_opp_table>;
 				status = "disabled";
 			};
 		};
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#20 lore raw

PATCH 6/21 scsi: ufs: Add support to manage multiple power domains in ufshcd-pltfrm

In reply to Rajendra Nayak

Some UFS devices need to manage multiple powerdomains. Add support for it as part of the ufshcd-pltfrm driver.

Cc Alim Akhtar <[email protected]>
Cc Can Guo <[email protected]>
Cc Asutosh Das <[email protected]>
Cc Subhash Jadavani <[email protected]>
---
 drivers/scsi/ufs/ufshcd-pltfrm.c | 58 ++++++++++++++++++++++++++++++++++++++--
 drivers/scsi/ufs/ufshcd.h        |  3 +++
 2 files changed, 59 insertions(+), 2 deletions(-)
drivers/scsi/ufs/ufshcd-pltfrm.c +56 -2
index 76f9be7..d40b4a7 100644
@@ -34,8 +34,10 @@
  */
 
 #include <linux/platform_device.h>
+#include <linux/pm_domain.h>
 #include <linux/pm_runtime.h>
 #include <linux/of.h>
+#include <linux/pm_opp.h>
 
 #include "ufshcd.h"
 #include "ufshcd-pltfrm.h"
@@ -282,6 +284,44 @@ static void ufshcd_init_lanes_per_dir(struct ufs_hba *hba)
 	}
 }
 
+static int ufshcd_attach_pds(struct device *dev, struct ufs_hba *hba, int num_pds)
+{
+	struct opp_table *opp;
+	struct device **opp_virt_dev;
+	const char *opp_pds[] = { "rpmh_pd", NULL };
+
+	if (num_pds > 2)
+		return -EINVAL;
+
+	/* Attach the power domain for on/off control */
+	hba->gdsc_virt_dev = dev_pm_domain_attach_by_name(dev, "gdsc_pd");
+	if (IS_ERR(hba->gdsc_virt_dev))
+		return PTR_ERR(hba->gdsc_virt_dev);
+
+	device_link_add(dev, hba->gdsc_virt_dev, DL_FLAG_RPM_ACTIVE |
+			DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS);
+
+
+	/* Attach the power domain for setting performance state */
+	opp = dev_pm_opp_attach_genpd(dev, opp_pds, &opp_virt_dev);
+	if (IS_ERR(opp))
+		return PTR_ERR(opp);
+	else if (opp_virt_dev) {
+		hba->opp_virt_dev = *opp_virt_dev;
+
+		device_link_add(dev, hba->opp_virt_dev, DL_FLAG_RPM_ACTIVE |
+				DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS);
+	}
+
+	return 0;
+}
+
+static void ufshcd_detach_pds(struct ufs_hba *hba)
+{
+	dev_pm_domain_detach(hba->gdsc_virt_dev, false);
+	dev_pm_domain_detach(hba->opp_virt_dev, false);
+}
+
 /**
  * ufshcd_get_pwr_dev_param - get finally agreed attributes for
  *                            power mode change
@@ -391,7 +431,7 @@ int ufshcd_pltfrm_init(struct platform_device *pdev,
 {
 	struct ufs_hba *hba;
 	void __iomem *mmio_base;
-	int irq, err;
+	int irq, err, num_pds;
 	struct device *dev = &pdev->dev;
 
 	mmio_base = devm_platform_ioremap_resource(pdev, 0);
@@ -429,10 +469,21 @@ int ufshcd_pltfrm_init(struct platform_device *pdev,
 
 	ufshcd_init_lanes_per_dir(hba);
 
+	num_pds = of_count_phandle_with_args(dev->of_node, "power-domains",
+					     "#power-domain-cells");
+	if (num_pds > 1) {
+		err = ufshcd_attach_pds(&pdev->dev, hba, num_pds);
+		if (err) {
+			dev_err(&pdev->dev, "%s: attach of power domains failed %d\n",
+				__func__, err);
+			goto dealloc_host;
+		}
+	}
+
 	err = ufshcd_init(hba, mmio_base, irq);
 	if (err) {
 		dev_err(dev, "Initialization failed\n");
-		goto dealloc_host;
+		goto detach_pds;
 	}
 
 	platform_set_drvdata(pdev, hba);
@@ -442,6 +493,9 @@ int ufshcd_pltfrm_init(struct platform_device *pdev,
 
 	return 0;
 
+detach_pds:
+	if (num_pds > 1)
+		ufshcd_detach_pds(hba);
 dealloc_host:
 	ufshcd_dealloc_host(hba);
 out:
drivers/scsi/ufs/ufshcd.h +3 -0
index dd1ee27..ed3fbad 100644
@@ -612,6 +612,9 @@ struct ufs_hba {
 	struct Scsi_Host *host;
 	struct device *dev;
 	struct request_queue *cmd_queue;
+	struct device *gdsc_virt_dev;
+	struct device *opp_virt_dev;
+
 	/*
 	 * This field is to keep a reference to "scsi_device" corresponding to
 	 * "UFS device" W-LU.
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#21 lore raw

PATCH 7/21 scsi: ufs: Add support for specifying OPP tables in DT

In reply to Rajendra Nayak

Some platforms like qualcomms sdm845 SoC have a need to set a performance state of a power domain for UFS along with setting the clock rate. Add support for passing this freq/perf state tuple from DT as an OPP table. Modify the driver to read the OPP table and register with OPP layer.

Cc Alim Akhtar <[email protected]>
Cc Can Guo <[email protected]>
Cc Asutosh Das <[email protected]>
Cc Subhash Jadavani <[email protected]>
---
 drivers/scsi/ufs/ufshcd.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/scsi/ufs/ufshcd.c +15 -2
index e04e8b8..172c6fe 100644
@@ -883,6 +883,16 @@ static int ufshcd_scale_clks(struct ufs_hba *hba, bool scale_up)
 	if (ret)
 		return ret;
 
+	if (hba->opp_virt_dev) {
+		struct dev_pm_opp *opp;
+		unsigned long freq = scale_up ? INT_MAX : 0;
+		if (scale_up)
+			opp = dev_pm_opp_find_freq_floor(hba->dev, &freq);
+		else
+			opp = dev_pm_opp_find_freq_ceil(hba->dev, &freq);
+		dev_pm_opp_set_rate(hba->dev, dev_pm_opp_get_freq(opp));
+	}
+
 	list_for_each_entry(clki, head, list) {
 		if (!IS_ERR_OR_NULL(clki->clk)) {
 			if (scale_up && clki->max_freq) {
@@ -1339,8 +1349,11 @@ static int ufshcd_devfreq_init(struct ufs_hba *hba)
 		return 0;
 
 	clki = list_first_entry(clk_list, struct ufs_clk_info, list);
-	dev_pm_opp_add(hba->dev, clki->min_freq, 0);
-	dev_pm_opp_add(hba->dev, clki->max_freq, 0);
+
+	if (dev_pm_opp_of_add_table(hba->dev)) {
+		dev_pm_opp_add(hba->dev, clki->min_freq, 0);
+		dev_pm_opp_add(hba->dev, clki->max_freq, 0);
+	}
 
 	ufshcd_vops_config_scaling_param(hba, &ufs_devfreq_profile,
 					 gov_data);
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#22 lore raw

PATCH 8/21 arm64: dts: sdm845: Add ufs opps and power-domains

In reply to Rajendra Nayak

Add the additional power domain and the OPP table for ufs on sdm845 so the driver can set the appropriate performance state of the power domain while setting the clock rate.

---
 arch/arm64/boot/dts/qcom/sdm845.dtsi | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/qcom/sdm845.dtsi +20 -1
index 36b9fb1..9a82f78 100644
@@ -1803,6 +1803,21 @@
 			qcom,bcm-voters = <&apps_bcm_voter>;
 		};
 
+		ufs_opp_table: ufs-opp-table {
+			compatible = "operating-points-v2";
+
+			opp-50000000 {
+				opp-hz = /bits/ 64 <50000000>;
+				required-opps = <&rpmhpd_opp_min_svs>;
+			};
+
+			opp-200000000 {
+				opp-hz = /bits/ 64 <200000000>;
+				required-opps = <&rpmhpd_opp_nom>;
+
+			};
+		};
+
 		ufs_mem_hc: ufshc@1d84000 {
 			compatible = "qcom,sdm845-ufshc", "qcom,ufshc",
 				     "jedec,ufs-2.0";
@@ -1811,7 +1826,8 @@
 			phys = <&ufs_mem_phy_lanes>;
 			phy-names = "ufsphy";
 			lanes-per-direction = <2>;
-			power-domains = <&gcc UFS_PHY_GDSC>;
+			power-domains = <&gcc UFS_PHY_GDSC>, <&rpmhpd SDM845_CX>;
+			power-domain-names = "gdsc_pd", "rpmh_pd";
 			#reset-cells = <1>;
 			resets = <&gcc GCC_UFS_PHY_BCR>;
 			reset-names = "rst";
@@ -1836,6 +1852,9 @@
 				<&gcc GCC_UFS_PHY_TX_SYMBOL_0_CLK>,
 				<&gcc GCC_UFS_PHY_RX_SYMBOL_0_CLK>,
 				<&gcc GCC_UFS_PHY_RX_SYMBOL_1_CLK>;
+
+			operating-points-v2 = <&ufs_opp_table>;
+
 			freq-table-hz =
 				<50000000 200000000>,
 				<0 0>,
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#23 lore raw

PATCH 9/21 drm/msm/dpu: Use OPP API to set clk/perf state

In reply to Rajendra Nayak

On some qualcomm platforms DPU needs to express a perforamnce state requirement on a power domain depending on 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.

---
 drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c | 3 ++-
 drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c       | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c +2 -1
index 11f2beb..fe5717df 100644
@@ -7,6 +7,7 @@
 #include <linux/debugfs.h>
 #include <linux/errno.h>
 #include <linux/mutex.h>
+#include <linux/pm_opp.h>
 #include <linux/sort.h>
 #include <linux/clk.h>
 #include <linux/bitmap.h>
@@ -239,7 +240,7 @@ static int _dpu_core_perf_set_core_clk_rate(struct dpu_kms *kms, u64 rate)
 		rate = core_clk->max_rate;
 
 	core_clk->rate = rate;
-	return msm_dss_clk_set_rate(core_clk, 1);
+	return dev_pm_opp_set_rate(&kms->pdev->dev, core_clk->rate);
 }
 
 static u64 _dpu_core_perf_get_core_clk_rate(struct dpu_kms *kms)
drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c +6 -0
index ce19f1d..949157a 100644
@@ -10,6 +10,7 @@
 #include <linux/debugfs.h>
 #include <linux/dma-buf.h>
 #include <linux/of_irq.h>
+#include <linux/pm_opp.h>
 
 #include <drm/drm_crtc.h>
 #include <drm/drm_file.h>
@@ -1033,6 +1034,9 @@ static int dpu_bind(struct device *dev, struct device *master, void *data)
 	if (!dpu_kms)
 		return -ENOMEM;
 
+	dev_pm_opp_set_clkname(dev, "core");
+	dev_pm_opp_of_add_table(dev);
+
 	mp = &dpu_kms->mp;
 	ret = msm_dss_parse_clock(pdev, mp);
 	if (ret) {
@@ -1059,6 +1063,7 @@ static void dpu_unbind(struct device *dev, struct device *master, void *data)
 	struct dpu_kms *dpu_kms = platform_get_drvdata(pdev);
 	struct dss_module_power *mp = &dpu_kms->mp;
 
+	dev_pm_opp_of_remove_table(dev);
 	msm_dss_put_clk(mp->clk_config, mp->num_clk);
 	devm_kfree(&pdev->dev, mp->clk_config);
 	mp->num_clk = 0;
@@ -1090,6 +1095,7 @@ static int __maybe_unused dpu_runtime_suspend(struct device *dev)
 	struct dpu_kms *dpu_kms = platform_get_drvdata(pdev);
 	struct dss_module_power *mp = &dpu_kms->mp;
 
+	dev_pm_opp_set_rate(dev, 0);
 	rc = msm_dss_enable_clk(mp->clk_config, mp->num_clk, false);
 	if (rc)
 		DPU_ERROR("clock disable failed rc:%d\n", rc);
Signature · 6 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#24 lore raw

PATCH 10/21 drm/msm: dsi: Use OPP API to set clk/perf state

In reply to Rajendra Nayak

On SDM845 DSI needs to express a perforamnce state requirement on a power domain depending on 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.

---
 drivers/gpu/drm/msm/dsi/dsi.h      |  2 ++
 drivers/gpu/drm/msm/dsi/dsi_cfg.c  |  4 ++--
 drivers/gpu/drm/msm/dsi/dsi_host.c | 48 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/dsi/dsi.h +2 -0
index 4de771d..ba7583c 100644
@@ -180,10 +180,12 @@ int msm_dsi_runtime_suspend(struct device *dev);
 int msm_dsi_runtime_resume(struct device *dev);
 int dsi_link_clk_set_rate_6g(struct msm_dsi_host *msm_host);
 int dsi_link_clk_set_rate_v2(struct msm_dsi_host *msm_host);
+int dsi_link_clk_set_rate_6g_v2(struct msm_dsi_host *msm_host);
 int dsi_link_clk_enable_6g(struct msm_dsi_host *msm_host);
 int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host);
 void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host);
 void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host);
+void dsi_link_clk_disable_6g_v2(struct msm_dsi_host *msm_host);
 int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size);
 int dsi_tx_buf_alloc_v2(struct msm_dsi_host *msm_host, int size);
 void *dsi_tx_buf_get_6g(struct msm_dsi_host *msm_host);
drivers/gpu/drm/msm/dsi/dsi_cfg.c +2 -2
index 813d69d..773c4fe 100644
@@ -210,9 +210,9 @@ static const struct msm_dsi_host_cfg_ops msm_dsi_6g_host_ops = {
 };
 
 static const struct msm_dsi_host_cfg_ops msm_dsi_6g_v2_host_ops = {
-	.link_clk_set_rate = dsi_link_clk_set_rate_6g,
+	.link_clk_set_rate = dsi_link_clk_set_rate_6g_v2,
 	.link_clk_enable = dsi_link_clk_enable_6g,
-	.link_clk_disable = dsi_link_clk_disable_6g,
+	.link_clk_disable = dsi_link_clk_disable_6g_v2,
 	.clk_init_ver = dsi_clk_init_6g_v2,
 	.tx_buf_alloc = dsi_tx_buf_alloc_6g,
 	.tx_buf_get = dsi_tx_buf_get_6g,
drivers/gpu/drm/msm/dsi/dsi_host.c +48 -0

84 lines not on this page · raw message

Signature · 6 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#25 lore raw

PATCH 11/21 arm64: dts: sdm845: Add DSI and MDP OPP tables and power-domains

In reply to Rajendra Nayak

Add the OPP tables for DSI and MDP based on the perf state/clk requirements, and add the power-domains property to specify the scalable power domain.

---
 arch/arm64/boot/dts/qcom/sdm845.dtsi | 59 ++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
arch/arm64/boot/dts/qcom/sdm845.dtsi +59 -0
index 9a82f78..7e3f022 100644
@@ -3328,6 +3328,59 @@
 			#reset-cells = <1>;
 		};
 
+		mdp_opp_table: mdp-opp-table {
+			compatible = "operating-points-v2";
+
+			opp-19200000 {
+				opp-hz = /bits/ 64 <19200000>;
+				required-opps = <&rpmhpd_opp_min_svs>;
+			};
+
+			opp-171428571 {
+				opp-hz = /bits/ 64 <171428571>;
+				required-opps = <&rpmhpd_opp_low_svs>;
+			};
+
+			opp-344000000 {
+				opp-hz = /bits/ 64 <344000000>;
+				required-opps = <&rpmhpd_opp_svs_l1>;
+			};
+
+			opp-430000000 {
+				opp-hz = /bits/ 64 <430000000>;
+				required-opps = <&rpmhpd_opp_nom>;
+			};
+		};
+
+		dsi_opp_table: dsi-opp-table {
+			compatible = "operating-points-v2";
+
+			opp-19200000 {
+				opp-hz = /bits/ 64 <19200000>;
+				required-opps = <&rpmhpd_opp_min_svs>;
+			};
+
+			opp-180000000 {
+				opp-hz = /bits/ 64 <180000000>;
+				required-opps = <&rpmhpd_opp_low_svs>;
+			};
+
+			opp-275000000 {
+				opp-hz = /bits/ 64 <275000000>;
+				required-opps = <&rpmhpd_opp_svs>;
+			};
+
+			opp-328580000 {
+				opp-hz = /bits/ 64 <328580000>;
+				required-opps = <&rpmhpd_opp_svs_l1>;
+			};
+
+			opp-358000000 {
+				opp-hz = /bits/ 64 <358000000>;
+				required-opps = <&rpmhpd_opp_nom>;
+			};
+		};
+
 		mdss: mdss@ae00000 {
 			compatible = "qcom,sdm845-mdss";
 			reg = <0 0x0ae00000 0 0x1000>;
@@ -3372,6 +3425,8 @@
 						  <&dispcc DISP_CC_MDSS_VSYNC_CLK>;
 				assigned-clock-rates = <300000000>,
 						       <19200000>;
+				operating-points-v2 = <&mdp_opp_table>;
+				power-domains = <&rpmhpd SDM845_CX>;
 
 				interrupt-parent = <&mdss>;
 				interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
@@ -3418,6 +3473,8 @@
 					      "core",
 					      "iface",
 					      "bus";
+				operating-points-v2 = <&dsi_opp_table>;
+				power-domains = <&rpmhpd SDM845_CX>;
 
 				phys = <&dsi0_phy>;
 				phy-names = "dsi";
@@ -3482,6 +3539,8 @@
 					      "core",
 					      "iface",
 					      "bus";
+				operating-points-v2 = <&dsi_opp_table>;
+				power-domains = <&rpmhpd SDM845_CX>;
 
 				phys = <&dsi1_phy>;
 				phy-names = "dsi";
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#26 lore raw

PATCH 12/21 arm64: dts: sc7180: Add DSI and MDP OPP tables and power-domains

In reply to Rajendra Nayak

Add the OPP tables for DSI and MDP based on the perf state/clk requirements, and add the power-domains property to specify the scalable power domain.

---
 arch/arm64/boot/dts/qcom/sc7180.dtsi | 48 ++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
arch/arm64/boot/dts/qcom/sc7180.dtsi +48 -0
index efba600..db5b3b3 100644
@@ -1581,6 +1581,49 @@
 			qcom,bcm-voters = <&apps_bcm_voter>;
 		};
 
+		mdp_opp_table: mdp-opp-table {
+			compatible = "operating-points-v2";
+
+			opp-200000000 {
+				opp-hz = /bits/ 64 <200000000>;
+				required-opps = <&rpmhpd_opp_low_svs>;
+			};
+
+			opp-300000000 {
+				opp-hz = /bits/ 64 <300000000>;
+				required-opps = <&rpmhpd_opp_svs>;
+			};
+
+			opp-345000000 {
+				opp-hz = /bits/ 64 <345000000>;
+				required-opps = <&rpmhpd_opp_svs_l1>;
+			};
+
+			opp-460000000 {
+				opp-hz = /bits/ 64 <460000000>;
+				required-opps = <&rpmhpd_opp_nom>;
+			};
+		};
+
+		dsi_opp_table: dsi-opp-table {
+			compatible = "operating-points-v2";
+
+			opp-187500000 {
+				opp-hz = /bits/ 64 <187500000>;
+				required-opps = <&rpmhpd_opp_low_svs>;
+			};
+
+			opp-300000000 {
+				opp-hz = /bits/ 64 <300000000>;
+				required-opps = <&rpmhpd_opp_svs>;
+			};
+
+			opp-358000000 {
+				opp-hz = /bits/ 64 <358000000>;
+				required-opps = <&rpmhpd_opp_svs_l1>;
+			};
+		};
+
 		mdss: mdss@ae00000 {
 			compatible = "qcom,sc7180-mdss";
 			reg = <0 0x0ae00000 0 0x1000>;
@@ -1626,6 +1669,8 @@
 						  <&dispcc DISP_CC_MDSS_VSYNC_CLK>;
 				assigned-clock-rates = <300000000>,
 						       <19200000>;
+				operating-points-v2 = <&mdp_opp_table>;
+				power-domains = <&rpmhpd SC7180_CX>;
 
 				interrupt-parent = <&mdss>;
 				interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
@@ -1666,6 +1711,9 @@
 					      "iface",
 					      "bus";
 
+				operating-points-v2 = <&dsi_opp_table>;
+				power-domains = <&rpmhpd SC7180_CX>;
+
 				phys = <&dsi_phy>;
 				phy-names = "dsi";
 
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#27 lore raw

PATCH 13/21 mmc: sdhci-msm: Use OPP API to set clk/perf state

In reply to Rajendra Nayak

On some qualcomm SoCs we need to vote on a performance state of a power domain depending on the clock rates. Hence move to using OPP api to set the clock rate and performance state specified in the OPP table. On platforms without an OPP table, dev_pm_opp_set_rate() is eqvivalent to clk_set_rate()

Cc Ulf Hansson <[email protected]>
Cc Pradeep P V K <[email protected]>
Cc Veerabhadrarao Badiganti <[email protected]>
Cc Subhash Jadavani <[email protected]>
---
 drivers/mmc/host/sdhci-msm.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
drivers/mmc/host/sdhci-msm.c +16 -4
index 09ff731..d82075a 100644
@@ -10,6 +10,7 @@
 #include <linux/delay.h>
 #include <linux/mmc/mmc.h>
 #include <linux/pm_runtime.h>
+#include <linux/pm_opp.h>
 #include <linux/slab.h>
 #include <linux/iopoll.h>
 #include <linux/regulator/consumer.h>
@@ -242,6 +243,7 @@ struct sdhci_msm_host {
 	struct clk *xo_clk;	/* TCXO clk needed for FLL feature of cm_dll*/
 	struct clk_bulk_data bulk_clks[4]; /* core, iface, cal, sleep clocks */
 	unsigned long clk_rate;
+	struct opp_table *opp;
 	struct mmc_host *mmc;
 	bool use_14lpp_dll_reset;
 	bool tuning_done;
@@ -332,7 +334,7 @@ static void msm_set_clock_rate_for_bus_mode(struct sdhci_host *host,
 	int rc;
 
 	clock = msm_get_clock_rate_for_bus_mode(host, clock);
-	rc = clk_set_rate(core_clk, clock);
+	rc = dev_pm_opp_set_rate(mmc_dev(host->mmc), clock);
 	if (rc) {
 		pr_err("%s: Failed to set clock at rate %u at timing %d\n",
 		       mmc_hostname(host->mmc), clock,
@@ -1963,7 +1965,7 @@ static int sdhci_msm_probe(struct platform_device *pdev)
 	msm_host->bulk_clks[0].clk = clk;
 
 	/* Vote for maximum clock rate for maximum performance */
-	ret = clk_set_rate(clk, INT_MAX);
+	ret = dev_pm_opp_set_rate(&pdev->dev, INT_MAX);
 	if (ret)
 		dev_warn(&pdev->dev, "core clock boost failed\n");
 
@@ -2087,6 +2089,9 @@ static int sdhci_msm_probe(struct platform_device *pdev)
 		goto clk_disable;
 	}
 
+	msm_host->opp = dev_pm_opp_set_clkname(&pdev->dev, "core");
+	dev_pm_opp_of_add_table(&pdev->dev);
+
 	pm_runtime_get_noresume(&pdev->dev);
 	pm_runtime_set_active(&pdev->dev);
 	pm_runtime_enable(&pdev->dev);
@@ -2109,10 +2114,12 @@ static int sdhci_msm_probe(struct platform_device *pdev)
 	return 0;
 
 pm_runtime_disable:
+	dev_pm_opp_of_remove_table(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 	pm_runtime_set_suspended(&pdev->dev);
 	pm_runtime_put_noidle(&pdev->dev);
 clk_disable:
+	dev_pm_opp_set_rate(&pdev->dev, 0);
 	clk_bulk_disable_unprepare(ARRAY_SIZE(msm_host->bulk_clks),
 				   msm_host->bulk_clks);
 bus_clk_disable:
@@ -2133,10 +2140,12 @@ static int sdhci_msm_remove(struct platform_device *pdev)
 
 	sdhci_remove_host(host, dead);
 
+	dev_pm_opp_of_remove_table(&pdev->dev);
 	pm_runtime_get_sync(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 	pm_runtime_put_noidle(&pdev->dev);
 
+	dev_pm_opp_set_rate(&pdev->dev, 0);
 	clk_bulk_disable_unprepare(ARRAY_SIZE(msm_host->bulk_clks),
 				   msm_host->bulk_clks);
 	if (!IS_ERR(msm_host->bus_clk))
@@ -2151,6 +2160,7 @@ static __maybe_unused int sdhci_msm_runtime_suspend(struct device *dev)
 	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
 	struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
 
+	dev_pm_opp_set_rate(dev, 0);
 	clk_bulk_disable_unprepare(ARRAY_SIZE(msm_host->bulk_clks),
 				   msm_host->bulk_clks);
 
@@ -2173,9 +2183,11 @@ static __maybe_unused int sdhci_msm_runtime_resume(struct device *dev)
 	 * restore the SDR DLL settings when the clock is ungated.
 	 */
 	if (msm_host->restore_dll_config && msm_host->clk_rate)
-		return sdhci_msm_restore_sdr_dll_config(host);
+		ret = sdhci_msm_restore_sdr_dll_config(host);
 
-	return 0;
+	dev_pm_opp_set_rate(dev, msm_host->clk_rate);
+
+	return ret;
 }
 
 static const struct dev_pm_ops sdhci_msm_pm_ops = {
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#34 lore raw

PATCH 15/21 arm64: dts: sc7180: Add sdhc opps and power-domains

In reply to Rajendra Nayak

Add the power domain supporting performance state and the corresponding OPP tables for the sdhc device on sdm845.

---
 arch/arm64/boot/dts/qcom/sc7180.dtsi | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
arch/arm64/boot/dts/qcom/sc7180.dtsi +16 -0
index db5b3b3..bcd0e6f 100644
@@ -390,6 +390,20 @@
 			};
 		};
 
+		sdhc1_opp_table: sdhc1-opp-table {
+			compatible = "operating-points-v2";
+
+			opp-100000000 {
+				opp-hz = /bits/ 64 <100000000>;
+				required-opps = <&rpmhpd_opp_low_svs>;
+			};
+
+			opp-384000000 {
+				opp-hz = /bits/ 64 <384000000>;
+				required-opps = <&rpmhpd_opp_svs_l1>;
+			};
+		};
+
 		sdhc_1: sdhci@7c4000 {
 			compatible = "qcom,sc7180-sdhci", "qcom,sdhci-msm-v5";
 			reg = <0 0x7c4000 0 0x1000>,
@@ -404,6 +418,8 @@
 			clocks = <&gcc GCC_SDCC1_APPS_CLK>,
 					<&gcc GCC_SDCC1_AHB_CLK>;
 			clock-names = "core", "iface";
+			power-domains = <&rpmhpd SC7180_CX>;
+			operating-points-v2 = <&sdhc1_opp_table>;
 
 			bus-width = <8>;
 			non-removable;
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#33 lore raw

PATCH 14/21 arm64: dts: sdm845: Add sdhc opps and power-domains

In reply to Rajendra Nayak

Add the power domain supporting performance state and the corresponding OPP tables for the sdhc device on sdm845.

---
 arch/arm64/boot/dts/qcom/sdm845.dtsi | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
arch/arm64/boot/dts/qcom/sdm845.dtsi +26 -0
index 7e3f022..6f2d503 100644
@@ -2994,6 +2994,30 @@
 			};
 		};
 
+		sdhc2_opp_table: sdhc2-opp-table {
+			compatible = "operating-points-v2";
+
+			opp-9600000 {
+				opp-hz = /bits/ 64 <9600000>;
+				required-opps = <&rpmhpd_opp_min_svs>;
+			};
+
+			opp-19200000 {
+				opp-hz = /bits/ 64 <19200000>;
+				required-opps = <&rpmhpd_opp_low_svs>;
+			};
+
+			opp-100000000 {
+				opp-hz = /bits/ 64 <100000000>;
+				required-opps = <&rpmhpd_opp_svs>;
+			};
+
+			opp-201500000 {
+				opp-hz = /bits/ 64 <201500000>;
+				required-opps = <&rpmhpd_opp_svs_l1>;
+			};
+		};
+
 		sdhc_2: sdhci@8804000 {
 			compatible = "qcom,sdm845-sdhci", "qcom,sdhci-msm-v5";
 			reg = <0 0x08804000 0 0x1000>;
@@ -3006,6 +3030,8 @@
 				 <&gcc GCC_SDCC2_APPS_CLK>;
 			clock-names = "iface", "core";
 			iommus = <&apps_smmu 0xa0 0xf>;
+			power-domains = <&rpmhpd SDM845_CX>;
+			operating-points-v2 = <&sdhc2_opp_table>;
 
 			status = "disabled";
 		};
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#35 lore raw

PATCH 16/21 media: venus: core: Add support for opp tables/perf voting

In reply to Rajendra Nayak

Add support to add OPP tables and perf voting on the OPP powerdomain. This is needed so venus votes on the corresponding performance state for the OPP powerdomain along with setting the core clock rate.

---
 drivers/media/platform/qcom/venus/core.c       | 16 +++++++++++
 drivers/media/platform/qcom/venus/core.h       |  4 +++
 drivers/media/platform/qcom/venus/pm_helpers.c | 37 +++++++++++++++++++++++---
 3 files changed, 53 insertions(+), 4 deletions(-)
drivers/media/platform/qcom/venus/core.c +16 -0
index 194b10b9..3853637 100644
@@ -12,6 +12,7 @@
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 #include <linux/types.h>
+#include <linux/pm_opp.h>
 #include <linux/pm_runtime.h>
 #include <media/videobuf2-v4l2.h>
 #include <media/v4l2-mem2mem.h>
@@ -250,6 +251,11 @@ static int venus_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	if (core->opp_pmdomain) {
+		core->opp = dev_pm_opp_set_clkname(dev, "core");
+		dev_pm_opp_of_add_table(dev);
+	}
+
 	pm_runtime_enable(dev);
 
 	ret = pm_runtime_get_sync(dev);
@@ -301,6 +307,8 @@ static int venus_probe(struct platform_device *pdev)
 err_venus_shutdown:
 	venus_shutdown(core);
 err_runtime_disable:
+	if (core->opp_pmdomain)
+		dev_pm_opp_of_remove_table(dev);
 	pm_runtime_set_suspended(dev);
 	pm_runtime_disable(dev);
 	hfi_destroy(core);
@@ -326,6 +334,9 @@ static int venus_remove(struct platform_device *pdev)
 
 	venus_firmware_deinit(core);
 
+	if (core->opp_pmdomain)
+		dev_pm_opp_of_remove_table(dev);
+
 	pm_runtime_put_sync(dev);
 	pm_runtime_disable(dev);
 
@@ -350,6 +361,9 @@ static __maybe_unused int venus_runtime_suspend(struct device *dev)
 	if (ret)
 		return ret;
 
+	if (core->opp_pmdomain)
+		dev_pm_opp_set_rate(dev, 0);
+
 	if (pm_ops->core_power)
 		ret = pm_ops->core_power(dev, POWER_OFF);
 
@@ -511,6 +525,7 @@ static const struct venus_resources sdm845_res_v2 = {
 	.vcodec_clks_num = 2,
 	.vcodec_pmdomains = { "venus", "vcodec0", "vcodec1" },
 	.vcodec_pmdomains_num = 3,
+	.opp_pmdomain = (const char *[]) { "opp-pd", NULL },
 	.vcodec_num = 2,
 	.max_load = 3110400,	/* 4096x2160@90 */
 	.hfi_version = HFI_VERSION_4XX,
@@ -556,6 +571,7 @@ static const struct venus_resources sc7180_res = {
 	.vcodec_clks_num = 2,
 	.vcodec_pmdomains = { "venus", "vcodec0" },
 	.vcodec_pmdomains_num = 2,
+	.opp_pmdomain = (const char *[]) { "opp-pd", NULL },
 	.vcodec_num = 1,
 	.hfi_version = HFI_VERSION_4XX,
 	.vmem_id = VIDC_RESOURCE_NONE,
drivers/media/platform/qcom/venus/core.h +4 -0
index bd3ac6a..90d011d 100644
@@ -62,6 +62,7 @@ struct venus_resources {
 	unsigned int vcodec_clks_num;
 	const char * const vcodec_pmdomains[VIDC_PMDOMAINS_NUM_MAX];
 	unsigned int vcodec_pmdomains_num;
+	const char **opp_pmdomain;
 	unsigned int vcodec_num;
 	enum hfi_version hfi_version;
 	u32 max_load;
@@ -144,8 +145,11 @@ struct venus_core {
 	struct clk *vcodec1_clks[VIDC_VCODEC_CLKS_NUM_MAX];
 	struct icc_path *video_path;
 	struct icc_path *cpucfg_path;
+	struct opp_table *opp;
 	struct device_link *pd_dl_venus;
 	struct device *pmdomains[VIDC_PMDOMAINS_NUM_MAX];
+	struct device_link *opp_dl_venus;
+	struct device *opp_pmdomain;
 	struct video_device *vdev_dec;
 	struct video_device *vdev_enc;
 	struct v4l2_device v4l2_dev;
drivers/media/platform/qcom/venus/pm_helpers.c +33 -4
index abf9315..b35ea7a 100644
@@ -9,6 +9,7 @@
 #include <linux/iopoll.h>
 #include <linux/kernel.h>
 #include <linux/pm_domain.h>
+#include <linux/pm_opp.h>
 #include <linux/pm_runtime.h>
 #include <linux/types.h>
 #include <media/v4l2-mem2mem.h>
@@ -66,10 +67,9 @@ static void core_clks_disable(struct venus_core *core)
 
 static int core_clks_set_rate(struct venus_core *core, unsigned long freq)
 {
-	struct clk *clk = core->clks[0];
 	int ret;
 
-	ret = clk_set_rate(clk, freq);
+	ret = dev_pm_opp_set_rate(core->dev, freq);
 	if (ret)
 		return ret;
 
@@ -740,13 +740,15 @@ static int venc_power_v4(struct device *dev, int on)
 
 static int vcodec_domains_get(struct device *dev)
 {
+	struct opp_table *opp;
+	struct device **opp_virt_dev;
 	struct venus_core *core = dev_get_drvdata(dev);
 	const struct venus_resources *res = core->res;
 	struct device *pd;
 	unsigned int i;
 
 	if (!res->vcodec_pmdomains_num)
-		return -ENODEV;
+		goto skip_pmdomains;
 
 	for (i = 0; i < res->vcodec_pmdomains_num; i++) {
 		pd = dev_pm_domain_attach_by_name(dev,
@@ -763,6 +765,24 @@ static int vcodec_domains_get(struct device *dev)
 	if (!core->pd_dl_venus)
 		return -ENODEV;
 
+skip_pmdomains:
+	if (!res->opp_pmdomain)
+		return 0;
+
+	/* Attach the power domain for setting performance state */
+	opp = dev_pm_opp_attach_genpd(dev, res->opp_pmdomain, &opp_virt_dev);
+	if (IS_ERR(opp))
+		return PTR_ERR(opp);
+	else if (opp_virt_dev) {
+		core->opp_pmdomain = *opp_virt_dev;
+		core->opp_dl_venus = device_link_add(dev, core->opp_pmdomain,
+						     DL_FLAG_RPM_ACTIVE |
+						     DL_FLAG_PM_RUNTIME |
+						     DL_FLAG_STATELESS);
+		if (!core->opp_dl_venus)
+			return -ENODEV;
+	}
+
 	return 0;
 }
 
@@ -773,7 +793,7 @@ static void vcodec_domains_put(struct device *dev)
 	unsigned int i;
 
 	if (!res->vcodec_pmdomains_num)
-		return;
+		goto skip_pmdomains;
 
 	if (core->pd_dl_venus)
 		device_link_del(core->pd_dl_venus);
@@ -783,6 +803,15 @@ static void vcodec_domains_put(struct device *dev)
 			continue;
 		dev_pm_domain_detach(core->pmdomains[i], true);
 	}
+
+skip_pmdomains:
+	if (!res->opp_pmdomain)
+		return;
+
+	if (core->opp_dl_venus)
+		device_link_del(core->opp_dl_venus);
+
+	dev_pm_domain_detach(core->opp_pmdomain, true);
 }
 
 static int core_get_v4(struct device *dev)
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#36 lore raw

PATCH 17/21 arm64: dts: sdm845: Add OPP tables and power-domains for venus

In reply to Rajendra Nayak

Add the OPP tables in order to be able to vote on the performance state of a power-domain.

---
 arch/arm64/boot/dts/qcom/sdm845.dtsi | 40 ++++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/sdm845.dtsi +38 -2
index 6f2d503..7e75de8 100644
@@ -3313,14 +3313,50 @@
 			};
 		};
 
+		venus_opp_table: venus-opp-table {
+			compatible = "operating-points-v2";
+
+			opp-100000000 {
+				opp-hz = /bits/ 64 <100000000>;
+				required-opps = <&rpmhpd_opp_min_svs>;
+			};
+
+			opp-200000000 {
+				opp-hz = /bits/ 64 <200000000>;
+				required-opps = <&rpmhpd_opp_low_svs>;
+			};
+
+			opp-320000000 {
+				opp-hz = /bits/ 64 <320000000>;
+				required-opps = <&rpmhpd_opp_svs>;
+			};
+
+			opp-380000000 {
+				opp-hz = /bits/ 64 <380000000>;
+				required-opps = <&rpmhpd_opp_svs_l1>;
+			};
+
+			opp-444000000 {
+				opp-hz = /bits/ 64 <444000000>;
+				required-opps = <&rpmhpd_opp_nom>;
+			};
+
+			opp-533000000 {
+				opp-hz = /bits/ 64 <533000000>;
+				required-opps = <&rpmhpd_opp_turbo>;
+			};
+		};
+
 		venus: video-codec@aa00000 {
 			compatible = "qcom,sdm845-venus-v2";
 			reg = <0 0x0aa00000 0 0xff000>;
 			interrupts = <GIC_SPI 174 IRQ_TYPE_LEVEL_HIGH>;
 			power-domains = <&videocc VENUS_GDSC>,
 					<&videocc VCODEC0_GDSC>,
-					<&videocc VCODEC1_GDSC>;
-			power-domain-names = "venus", "vcodec0", "vcodec1";
+					<&videocc VCODEC1_GDSC>,
+					<&rpmhpd SDM845_CX>;
+			power-domain-names = "venus", "vcodec0", "vcodec1", "opp-pd";
+			operating-points-v2 = <&venus_opp_table>;
 			clocks = <&videocc VIDEO_CC_VENUS_CTL_CORE_CLK>,
 				 <&videocc VIDEO_CC_VENUS_AHB_CLK>,
 				 <&videocc VIDEO_CC_VENUS_CTL_AXI_CLK>,
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#37 lore raw

PATCH 18/21 arm64: dts: sc7180: Add OPP tables and power-domains for venus

In reply to Rajendra Nayak

Add the OPP tables in order to be able to vote on the performance state of a power-domain

---
 arch/arm64/boot/dts/qcom/sc7180.dtsi | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/sc7180.dtsi +33 -2
index bcd0e6f..b87f3eb 100644
@@ -1554,13 +1554,44 @@
 			};
 		};
 
+		venus_opp_table: venus-opp-table {
+			compatible = "operating-points-v2";
+
+			opp-200000000 {
+				opp-hz = /bits/ 64 <150000000>;
+				required-opps = <&rpmhpd_opp_low_svs>;
+			};
+
+			opp-320000000 {
+				opp-hz = /bits/ 64 <270000000>;
+				required-opps = <&rpmhpd_opp_svs>;
+			};
+
+			opp-380000000 {
+				opp-hz = /bits/ 64 <340000000>;
+				required-opps = <&rpmhpd_opp_svs_l1>;
+			};
+
+			opp-444000000 {
+				opp-hz = /bits/ 64 <434000000>;
+				required-opps = <&rpmhpd_opp_nom>;
+			};
+
+			opp-533000000 {
+				opp-hz = /bits/ 64 <500000000>;
+				required-opps = <&rpmhpd_opp_turbo>;
+			};
+		};
+
 		venus: video-codec@aa00000 {
 			compatible = "qcom,sc7180-venus";
 			reg = <0 0x0aa00000 0 0xff000>;
 			interrupts = <GIC_SPI 174 IRQ_TYPE_LEVEL_HIGH>;
 			power-domains = <&videocc VENUS_GDSC>,
-					<&videocc VCODEC0_GDSC>;
-			power-domain-names = "venus", "vcodec0";
+					<&videocc VCODEC0_GDSC>,
+					<&rpmhpd SC7180_CX>;
+			power-domain-names = "venus", "vcodec0", "opp-pd";
+			operating-points-v2 = <&venus_opp_table>;
 			clocks = <&videocc VIDEO_CC_VENUS_CTL_CORE_CLK>,
 				 <&videocc VIDEO_CC_VENUS_AHB_CLK>,
 				 <&videocc VIDEO_CC_VENUS_CTL_AXI_CLK>,
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#39 lore raw

PATCH 20/21 arm64: dts: sdm845: Add qspi opps and power-domains

In reply to Rajendra Nayak

Add the power domain supporting performance state and the corresponding OPP tables for the qspi device on sdm845

---
 arch/arm64/boot/dts/qcom/sdm845.dtsi | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
arch/arm64/boot/dts/qcom/sdm845.dtsi +26 -0
index 7e75de8..7ccf24d 100644
@@ -3036,6 +3036,30 @@
 			status = "disabled";
 		};
 
+		qspi_opp_table: qspi-opp-table {
+			compatible = "operating-points-v2";
+
+			opp-19200000 {
+				opp-hz = /bits/ 64 <19200000>;
+				required-opps = <&rpmhpd_opp_min_svs>;
+			};
+
+			opp-100000000 {
+				opp-hz = /bits/ 64 <100000000>;
+				required-opps = <&rpmhpd_opp_low_svs>;
+			};
+
+			opp-150000000 {
+				opp-hz = /bits/ 64 <150000000>;
+				required-opps = <&rpmhpd_opp_svs>;
+			};
+
+			opp-300000000 {
+				opp-hz = /bits/ 64 <300000000>;
+				required-opps = <&rpmhpd_opp_nom>;
+			};
+		};
+
 		qspi: spi@88df000 {
 			compatible = "qcom,sdm845-qspi", "qcom,qspi-v1";
 			reg = <0 0x088df000 0 0x600>;
@@ -3045,6 +3069,8 @@
 			clocks = <&gcc GCC_QSPI_CNOC_PERIPH_AHB_CLK>,
 				 <&gcc GCC_QSPI_CORE_CLK>;
 			clock-names = "iface", "core";
+			power-domains = <&rpmhpd SDM845_CX>;
+			operating-points-v2 = <&qspi_opp_table>;
 			status = "disabled";
 		};
 
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#38 lore raw

PATCH 19/21 spi: spi-qcom-qspi: Use OPP API to set clk/perf state

In reply to Rajendra Nayak

QSPI needs to vote on a performance state of a power domain depending on the clock rate. Add support for it by specifying the perf state/clock rate as an OPP table in device tree.

---
 drivers/spi/spi-qcom-qspi.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/spi/spi-qcom-qspi.c +9 -1
index 3c4f83b..42a9511 100644
@@ -8,6 +8,7 @@
 #include <linux/of.h>
 #include <linux/of_platform.h>
 #include <linux/pm_runtime.h>
+#include <linux/pm_opp.h>
 #include <linux/spi/spi.h>
 #include <linux/spi/spi-mem.h>
 
@@ -235,7 +236,7 @@ static int qcom_qspi_transfer_one(struct spi_master *master,
 		speed_hz = xfer->speed_hz;
 
 	/* In regular operation (SBL_EN=1) core must be 4x transfer clock */
-	ret = clk_set_rate(ctrl->clks[QSPI_CLK_CORE].clk, speed_hz * 4);
+	ret = dev_pm_opp_set_rate(ctrl->dev, speed_hz * 4);
 	if (ret) {
 		dev_err(ctrl->dev, "Failed to set core clk %d\n", ret);
 		return ret;
@@ -481,6 +482,9 @@ static int qcom_qspi_probe(struct platform_device *pdev)
 	master->handle_err = qcom_qspi_handle_err;
 	master->auto_runtime_pm = true;
 
+	dev_pm_opp_set_clkname(&pdev->dev, "core");
+	dev_pm_opp_of_add_table(&pdev->dev);
+
 	pm_runtime_enable(dev);
 
 	ret = spi_register_master(master);
@@ -490,6 +494,7 @@ static int qcom_qspi_probe(struct platform_device *pdev)
 	pm_runtime_disable(dev);
 
 exit_probe_master_put:
+	dev_pm_opp_of_remove_table(&pdev->dev);
 	spi_master_put(master);
 
 	return ret;
@@ -499,6 +504,8 @@ static int qcom_qspi_remove(struct platform_device *pdev)
 {
 	struct spi_master *master = platform_get_drvdata(pdev);
 
+	dev_pm_opp_of_remove_table(&pdev->dev);
+
 	/* Unregister _before_ disabling pm_runtime() so we stop transfers */
 	spi_unregister_master(master);
 
@@ -512,6 +519,7 @@ static int __maybe_unused qcom_qspi_runtime_suspend(struct device *dev)
 	struct spi_master *master = dev_get_drvdata(dev);
 	struct qcom_qspi *ctrl = spi_master_get_devdata(master);
 
+	dev_pm_opp_set_rate(dev, 0);
 	clk_bulk_disable_unprepare(QSPI_NUM_CLKS, ctrl->clks);
 
 	return 0;
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#40 lore raw

PATCH 21/21 arm64: dts: sc7180: Add qspi opps and power-domains

In reply to Rajendra Nayak

Add the power domain supporting performance state and the corresponding OPP tables for the qspi device on sc7180

---
 arch/arm64/boot/dts/qcom/sc7180.dtsi | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
arch/arm64/boot/dts/qcom/sc7180.dtsi +21 -0
index b87f3eb..c340a63 100644
@@ -1421,6 +1421,25 @@
 			#power-domain-cells = <1>;
 		};
 
+		qspi_opp_table: qspi-opp-table {
+			compatible = "operating-points-v2";
+
+			opp-75000000 {
+				opp-hz = /bits/ 64 <75000000>;
+				required-opps = <&rpmhpd_opp_low_svs>;
+			};
+
+			opp-150000000 {
+				opp-hz = /bits/ 64 <150000000>;
+				required-opps = <&rpmhpd_opp_svs>;
+			};
+
+			opp-300000000 {
+				opp-hz = /bits/ 64 <300000000>;
+				required-opps = <&rpmhpd_opp_nom>;
+			};
+		};
+
 		qspi: spi@88dc000 {
 			compatible = "qcom,qspi-v1";
 			reg = <0 0x088dc000 0 0x600>;
@@ -1430,6 +1449,8 @@
 			clocks = <&gcc GCC_QSPI_CNOC_PERIPH_AHB_CLK>,
 				 <&gcc GCC_QSPI_CORE_CLK>;
 			clock-names = "iface", "core";
+			power-domains = <&rpmhpd SC7180_CX>;
+			operating-points-v2 = <&qspi_opp_table>;
 			status = "disabled";
 		};
 
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#2 lore raw

Re: [PATCH 01/21] opp: Manage empty OPP tables with clk handle

In reply to Rajendra Nayak
Quoted 2 lines · Rajendra Nayak

With OPP core now supporting DVFS for IO devices, we have instances of IO devices (same IP block) which require an OPP on some platforms/SoCs

By OPP you mean both freq and voltage here ?

Quoted 1 line

while just needing to scale the clock on some others.

And only freq here ?

Quoted 4 lines

In order to avoid conditional code in every driver which supports such devices (to check for availability of OPPs and then deciding to do either dev_pm_opp_set_rate() or clk_set_rate()) add support to manage empty OPP tables with a clk handle.

Why can't these devices have an opp table with just rate mentioned in each node ?

Quoted 14 lines

This makes dev_pm_opp_set_rate() equivalent of a clk_set_rate() for devices with just a clk and no OPPs specified, and makes dev_pm_opp_set_rate(0) bail out without throwing an error.

---
 drivers/opp/core.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/opp/core.c +0 -0
index ba43e6a..e4f01e7 100644

drivers/opp/core.c int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) · line 823

Quoted 5 lines
drivers/opp/core.c +2 -0
@@ -819,6 +819,8 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
 	if (unlikely(!target_freq)) {
 		if (opp_table->required_opp_tables) {
 			ret = _set_required_opps(dev, opp_table, NULL);
+		} else if (!_get_opp_count(opp_table)) {
+			return 0;

Why should anyone call this with target_freq = 0 ? I know it was required to drop votes in the above case, but why here ?

Quoted 9 lines
drivers/opp/core.c +2 -0
 		} else {
 			dev_err(dev, "target frequency can't be 0\n");
 			ret = -EINVAL;
@@ -849,6 +851,18 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
 		goto put_opp_table;
 	}
 
+	/*
+	 * For IO devices which require an OPP on some platforms/SoCs

drivers/opp/core.c int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) · line 865

Quoted 10 lines
drivers/opp/core.c +10 -0
+	 * while just needing to scale the clock on some others
+	 * we look for empty OPP tables with just a clock handle and
+	 * scale only the clk. This makes dev_pm_opp_set_rate()
+	 * equivalent to a clk_set_rate()
+	 */
+	if (!_get_opp_count(opp_table)) {
+		ret = _generic_set_opp_clk_only(dev, clk, freq);
+		goto put_opp_table;
+	}
+

Is this enough? _of_add_opp_table_v2() returns with error if there is no OPP node within the table. Please give an example of how DT looks for the case you want to support.

Quoted 6 lines
drivers/opp/core.c +0 -0
 	temp_freq = old_freq;
 	old_opp = _find_freq_ceil(opp_table, &temp_freq);
 	if (IS_ERR(old_opp)) {
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
Signature · 1 line
viresh
#7 lore raw

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

In reply to Rajendra Nayak

Hi Rajendra,

Quoted 47 lines · Rajendra Nayak

geni serial needs to express a perforamnce state requirement on CX 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.

---
 drivers/tty/serial/qcom_geni_serial.c | 20 +++++++++++++++-----
 include/linux/qcom-geni-se.h          |  2 ++
 2 files changed, 17 insertions(+), 5 deletions(-)
drivers/tty/serial/qcom_geni_serial.c +5 -2
index 6119090..754eaf6 100644
@@ -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>
@@ -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;
 
@@ -1198,8 +1199,10 @@ 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) {
+		dev_pm_opp_set_rate(uport->dev, 0);
 		geni_se_resources_off(&port->se);
+	}
 }
 
 static const struct uart_ops qcom_geni_console_pops = {

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

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c +1 -0
@@ -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_set_clkname() can fail for multiple reasons, it seems an error check would be warranted.

Is it actually necessary to save the OPP table in 'struct geni_se'? Both the serial and the SPI driver save the table, but don't use it later (nor does the SE driver).

#16 lore raw

Re: [PATCH 03/21] spi: spi-geni-qcom: Use OPP API to set clk/perf state

In reply to Rajendra Nayak

Hi Rajendra,

Quoted 54 lines · Rajendra Nayak

geni spi needs to express a perforamnce state requirement on CX 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.

---
 drivers/spi/spi-geni-qcom.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/spi/spi-geni-qcom.c +4 -3
index c397242..ce387dc 100644
@@ -7,6 +7,7 @@
 #include <linux/log2.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/pm_opp.h>
 #include <linux/pm_runtime.h>
 #include <linux/qcom-geni-se.h>
 #include <linux/spi/spi.h>
@@ -95,7 +96,6 @@ static int get_spi_clk_cfg(unsigned int speed_hz,
 {
 	unsigned long sclk_freq;
 	unsigned int actual_hz;
-	struct geni_se *se = &mas->se;
 	int ret;
 
 	ret = geni_se_clk_freq_match(&mas->se,
@@ -112,9 +112,9 @@ static int get_spi_clk_cfg(unsigned int speed_hz,
 
 	dev_dbg(mas->dev, "req %u=>%u sclk %lu, idx %d, div %d\n", speed_hz,
 				actual_hz, sclk_freq, *clk_idx, *clk_div);
-	ret = clk_set_rate(se->clk, sclk_freq);
+	ret = dev_pm_opp_set_rate(mas->dev, sclk_freq);
 	if (ret)
-		dev_err(mas->dev, "clk_set_rate failed %d\n", ret);
+		dev_err(mas->dev, "dev_pm_opp_set_rate failed %d\n", ret);
 	return ret;
 }
 
@@ -553,6 +553,7 @@ static int spi_geni_probe(struct platform_device *pdev)
 	if (!spi)
 		return -ENOMEM;
 
+
 	platform_set_drvdata(pdev, spi);
 	mas = spi_master_get_devdata(spi);
 	mas->irq = irq;

drivers/spi/spi-geni-qcom.c static int spi_geni_probe(struct platform_device *pdev) · line 565

Quoted 4 lines
drivers/spi/spi-geni-qcom.c +1 -0
@@ -561,6 +562,8 @@ static int spi_geni_probe(struct platform_device *pdev)
 	mas->se.wrapper = dev_get_drvdata(dev->parent);
 	mas->se.base = base;
 	mas->se.clk = clk;
+	mas->se.opp = dev_pm_opp_set_clkname(&pdev->dev, "se");

As commented on the serial patch, it seems an error check is needed and the OPP table saved in 'struct geni_se' is never used.

drivers/spi/spi-geni-qcom.c static int spi_geni_probe(struct platform_device *pdev) · line 566

Quoted 1 line
drivers/spi/spi-geni-qcom.c +1 -0
+	dev_pm_opp_of_add_table(&pdev->dev);

This function could also fail for multiple reasons, so the return value should be checked.

From patch "[01/21] opp: Manage empty OPP tables with clk handle" it seems ignoring errors is intended to be able to operate when no OPP table is specified. But even with that you want to return in case of certain errors, like an invalid OPP table, out of memory or -EPROBE_DEFER.

#12 lore raw

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

In reply to Rajendra Nayak

Hi Rajendra,

Quoted 1 line · Rajendra Nayak

geni serial needs to express a perforamnce state requirement on CX

*performance

Quoted 25 lines

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.

---
  drivers/tty/serial/qcom_geni_serial.c | 20 +++++++++++++++-----
  include/linux/qcom-geni-se.h          |  2 ++
  2 files changed, 17 insertions(+), 5 deletions(-)
drivers/tty/serial/qcom_geni_serial.c +1 -0
index 6119090..754eaf6 100644
@@ -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>

drivers/tty/serial/qcom_geni_serial.c static void qcom_geni_serial_set_termios(struct uart_port *uport, · line 965

Quoted 5 lines
drivers/tty/serial/qcom_geni_serial.c +1 -1
@@ -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);

Is this change not intended for backward compatibility? If I don't pick DT change for Geni drivers,  dev_pm_opp_set_rate is failing and causing functionality issues.

Quoted 44 lines
drivers/tty/serial/qcom_geni_serial.c +8 -3
  	ser_clk_cfg = SER_CLK_EN;
  	ser_clk_cfg |= clk_div << CLK_DIV_SHFT;
 
@@ -1198,8 +1199,10 @@ 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) {
+		dev_pm_opp_set_rate(uport->dev, 0);
  		geni_se_resources_off(&port->se);
+	}
  }
 
  static const struct uart_ops qcom_geni_console_pops = {
@@ -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) {

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

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c +3 -1
  			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");?

Regards,
Akash

Quoted 32 lines
drivers/tty/serial/qcom_geni_serial.c +2 -0
+	return ret;
  }
 
  static int qcom_geni_serial_remove(struct platform_device *pdev)
@@ -1361,6 +1370,7 @@ 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;
 
+	dev_pm_opp_of_remove_table(&pdev->dev);
  	dev_pm_clear_wake_irq(&pdev->dev);
  	device_init_wakeup(&pdev->dev, false);
  	uart_remove_one_port(drv, &port->uport);
include/linux/qcom-geni-se.h +2 -0
index dd46494..737e713 100644
@@ -24,6 +24,7 @@ enum geni_se_protocol_type {
 
  struct geni_wrapper;
  struct clk;
+struct opp_table;
 
  /**
   * struct geni_se - GENI Serial Engine
@@ -39,6 +40,7 @@ struct geni_se {
  	struct device *dev;
  	struct geni_wrapper *wrapper;
  	struct clk *clk;
+	struct opp_table *opp;
  	unsigned int num_clk_levels;
  	unsigned long *clk_perf_tbl;
  };
Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project
#8 lore raw

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

In reply to Matthias Kaehlcke
Quoted 6 lines

drivers/tty/serial/qcom_geni_serial.c static void qcom_geni_serial_set_termios(struct uart_port *uport, · line 965

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c +1 -1
@@ -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);

Hi Rajendra,

I see lowest rpmhpd_opp_low_svs opp is for 75MHz. It is a bit higher for a serial.
I am just curious about this.

I also want to confirm that the rpmhpd_opp_low_svs voltage restriction is for serial
controller, not for clock controller? Because I see there is similar restriction to clock
controller on another platform, the restriction is for branch clock, not leaf clock that
consumer device will get.

Jun

#13 lore raw

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

In reply to Akash Asthana

Hi Rajendra,

Quoted 29 lines · Akash Asthana

Hi Rajendra,

Quoted 1 line · Rajendra Nayak

geni serial needs to express a perforamnce state requirement on CX

*performance

Quoted 24 lines

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.

---
  drivers/tty/serial/qcom_geni_serial.c | 20 +++++++++++++++----- include/linux/qcom-geni-se.h          |  2 ++

  2 files changed, 17 insertions(+), 5 deletions(-)
drivers/tty/serial/qcom_geni_serial.c +1 -0
index 6119090..754eaf6 100644
@@ -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>
Quoted 8 lines

drivers/tty/serial/qcom_geni_serial.c static void qcom_geni_serial_set_termios(struct · line 965

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c +1 -1
@@ -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);

Is this change not intended for backward compatibility? If I don't pick DT change for Geni drivers,  dev_pm_opp_set_rate is failing and causing functionality issues.

oops Sorry, 1st patch is intended for backward compatibility. Which I missed earlier.

Regards,

Akash

Quoted 88 lines
Quoted 41 lines
drivers/tty/serial/qcom_geni_serial.c +0 -0
       ser_clk_cfg = SER_CLK_EN;
       ser_clk_cfg |= clk_div << CLK_DIV_SHFT;
   @@ -1198,8 +1199,10 @@ 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) {
+        dev_pm_opp_set_rate(uport->dev, 0); geni_se_resources_off(&port->se);
+    }
  }
    static const struct uart_ops qcom_geni_console_pops = {

drivers/tty/serial/qcom_geni_serial.c +4 -2
@@ -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)

drivers/tty/serial/qcom_geni_serial.c static int qcom_geni_serial_probe(struct · line 1364

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c +3 -1
           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");?

Regards,
Akash

Quoted 29 lines
drivers/tty/serial/qcom_geni_serial.c +1 -0
+    return ret;
   }
     static int qcom_geni_serial_remove(struct platform_device *pdev)
@@ -1361,6 +1370,7 @@ 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;
   +    dev_pm_opp_of_remove_table(&pdev->dev);
       dev_pm_clear_wake_irq(&pdev->dev);
       device_init_wakeup(&pdev->dev, false);

      uart_remove_one_port(drv, &port->uport);

include/linux/qcom-geni-se.h +2 -0
index dd46494..737e713 100644
@@ -24,6 +24,7 @@ enum geni_se_protocol_type {
     struct geni_wrapper;
   struct clk;
+struct opp_table;
     /**
    * struct geni_se - GENI Serial Engine
@@ -39,6 +40,7 @@ struct geni_se {
       struct device *dev;
       struct geni_wrapper *wrapper;
       struct clk *clk;
+    struct opp_table *opp;
       unsigned int num_clk_levels;
       unsigned long *clk_perf_tbl;
   };
Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project
#3 lore raw

Re: [PATCH 01/21] opp: Manage empty OPP tables with clk handle

In reply to Viresh Kumar
Quoted 5 lines · Viresh Kumar
Quoted 2 lines · Rajendra Nayak

With OPP core now supporting DVFS for IO devices, we have instances of IO devices (same IP block) which require an OPP on some platforms/SoCs

By OPP you mean both freq and voltage here ?

yes, freq and perf state.

Quoted 4 lines
Quoted 2 lines

while just needing to scale the clock on some others.

And only freq here ?

yes.

Quoted 8 lines
Quoted 5 lines

In order to avoid conditional code in every driver which supports such devices (to check for availability of OPPs and then deciding to do either dev_pm_opp_set_rate() or clk_set_rate()) add support to manage empty OPP tables with a clk handle.

Why can't these devices have an opp table with just rate mentioned in each node ?

These are existing devices already upstream.

Quoted 10 lines
Quoted 10 lines

This makes dev_pm_opp_set_rate() equivalent of a clk_set_rate() for devices with just a clk and no OPPs specified, and makes dev_pm_opp_set_rate(0) bail out without throwing an error.

---
  drivers/opp/core.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
Quoted 13 lines

drivers/opp/core.c int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) · line 823

Quoted 10 lines
drivers/opp/core.c +2 -0
index ba43e6a..e4f01e7 100644
@@ -819,6 +819,8 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
  	if (unlikely(!target_freq)) {
  		if (opp_table->required_opp_tables) {
  			ret = _set_required_opps(dev, opp_table, NULL);
+		} else if (!_get_opp_count(opp_table)) {
+			return 0;

Why should anyone call this with target_freq = 0 ? I know it was required to drop votes in the above case, but why here ?

Well, it is to drop votes. But in cases where we don't have perf votes being put (and only clock is scaled), the driver would still call this with freq = 0, i am just making sure that in such cases its treated as a nop.

Quoted 8 lines
Quoted 8 lines
drivers/opp/core.c +0 -0
  		} else {
  			dev_err(dev, "target frequency can't be 0\n");
  			ret = -EINVAL;
@@ -849,6 +851,18 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
  		goto put_opp_table;
  	}
 
Quoted 16 lines

drivers/opp/core.c int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) · line 865

Quoted 12 lines
drivers/opp/core.c +12 -0
+	/*
+	 * For IO devices which require an OPP on some platforms/SoCs
+	 * while just needing to scale the clock on some others
+	 * we look for empty OPP tables with just a clock handle and
+	 * scale only the clk. This makes dev_pm_opp_set_rate()
+	 * equivalent to a clk_set_rate()
+	 */
+	if (!_get_opp_count(opp_table)) {
+		ret = _generic_set_opp_clk_only(dev, clk, freq);
+		goto put_opp_table;
+	}
+

Is this enough? _of_add_opp_table_v2() returns with error if there is no OPP node within the table. Please give an example of how DT looks for the case you want to support.

FWIK, no one should call a _of_add_opp_table_v2 in cases where there is no OPP in DT? The 'empty' OPP table from what I understand will be created by dev_pm_opp_set_clkname. A good case to look at is the PATCH 13/21 in this series. The driver I am modifying is used on sdm845/sc7180 and a host of other older qualcomm SoCs. Since i am adding support for perf state voting using OPP only on sdm845/sc7180 I want the existing platforms to just do what they were doing. Now thats not possible unless I start adding a bunch of if/else around every opp call in the driver to distinguish between the two.

I am a little surprised since I though the idea of doing something like this came from you :) (or perhaps Stephen, I somehow can't recollect) to avoid all the if/else conditions I had when I initially posted some of these changes.
Btw, you had this patch reviewed when this was posted a long while back too [1]

[1] https://patchwork.kernel.org/patch/11027217/

Quoted 8 lines
Quoted 7 lines
drivers/opp/core.c +0 -0
  	temp_freq = old_freq;
  	old_opp = _find_freq_ceil(opp_table, &temp_freq);
  	if (IS_ERR(old_opp)) {
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#4 lore raw

Re: [PATCH 01/21] opp: Manage empty OPP tables with clk handle

Quoted 11 lines · Rajendra Nayak

FWIK, no one should call a _of_add_opp_table_v2 in cases where there is no OPP in DT? The 'empty' OPP table from what I understand will be created by dev_pm_opp_set_clkname. A good case to look at is the PATCH 13/21 in this series. The driver I am modifying is used on sdm845/sc7180 and a host of other older qualcomm SoCs. Since i am adding support for perf state voting using OPP only on sdm845/sc7180 I want the existing platforms to just do what they were doing. Now thats not possible unless I start adding a bunch of if/else around every opp call in the driver to distinguish between the two.

I am a little surprised since I though the idea of doing something like this came from you :) (or perhaps Stephen, I somehow can't recollect)

Me only as I start remembering it now :)

Quoted 5 lines

to avoid all the if/else conditions
I had when I initially posted some of these changes.
Btw, you had this patch reviewed when this was posted a long while back too [1]

[1] https://patchwork.kernel.org/patch/11027217/

That's an year back, in my defence :)

But anyway, I wasn't opposed to the idea now as well. I was just making sure all things are handled well :)

Signature · 1 line
viresh
#11 lore raw

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

In reply to Matthias Kaehlcke

Hi Matthias,

Quoted 53 lines · Matthias Kaehlcke

Hi Rajendra,

Quoted 50 lines · Rajendra Nayak

geni serial needs to express a perforamnce state requirement on CX 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.

---
  drivers/tty/serial/qcom_geni_serial.c | 20 +++++++++++++++-----
  include/linux/qcom-geni-se.h          |  2 ++
  2 files changed, 17 insertions(+), 5 deletions(-)
drivers/tty/serial/qcom_geni_serial.c +5 -2
index 6119090..754eaf6 100644
@@ -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>
@@ -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;
 
@@ -1198,8 +1199,10 @@ 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) {
+		dev_pm_opp_set_rate(uport->dev, 0);
  		geni_se_resources_off(&port->se);
+	}
  }
 
  static const struct uart_ops qcom_geni_console_pops = {
@@ -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;
 
Quoted 4 lines

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

Quoted 1 line
drivers/tty/serial/qcom_geni_serial.c +1 -0
+	port->se.opp = dev_pm_opp_set_clkname(&pdev->dev, "se");

dev_pm_opp_set_clkname() can fail for multiple reasons, it seems an error check would be warranted.

right, looks like I should put some error check there

Quoted 3 lines

Is it actually necessary to save the OPP table in 'struct geni_se'? Both the serial and the SPI driver save the table, but don't use it later (nor does the SE driver).

I think I did that initially because I wanted to use that to call into dev_pm_opp_put_clkname during cleanup. That however never worked since the way the clk_put is done in dev_pm_opp_put_clkname() and _opp_table_kref_release() seems buggy. I kind of forgot about fixing it up, I will figure our whats the right way to do it, and either not call dev_pm_opp_put_clkname() or not store the opp table returned by it.

thanks for taking time to review.

- Rajendra

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#17 lore raw

Re: [PATCH 03/21] spi: spi-geni-qcom: Use OPP API to set clk/perf state

In reply to Matthias Kaehlcke
Quoted 52 lines · Matthias Kaehlcke

Hi Rajendra,

Quoted 49 lines · Rajendra Nayak

geni spi needs to express a perforamnce state requirement on CX 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.

---
  drivers/spi/spi-geni-qcom.c | 14 +++++++++++---
  1 file changed, 11 insertions(+), 3 deletions(-)
drivers/spi/spi-geni-qcom.c +3 -3
index c397242..ce387dc 100644
@@ -7,6 +7,7 @@
  #include <linux/log2.h>
  #include <linux/module.h>
  #include <linux/platform_device.h>
+#include <linux/pm_opp.h>
  #include <linux/pm_runtime.h>
  #include <linux/qcom-geni-se.h>
  #include <linux/spi/spi.h>
@@ -95,7 +96,6 @@ static int get_spi_clk_cfg(unsigned int speed_hz,
  {
  	unsigned long sclk_freq;
  	unsigned int actual_hz;
-	struct geni_se *se = &mas->se;
  	int ret;
 
  	ret = geni_se_clk_freq_match(&mas->se,
@@ -112,9 +112,9 @@ static int get_spi_clk_cfg(unsigned int speed_hz,
 
  	dev_dbg(mas->dev, "req %u=>%u sclk %lu, idx %d, div %d\n", speed_hz,
  				actual_hz, sclk_freq, *clk_idx, *clk_div);
-	ret = clk_set_rate(se->clk, sclk_freq);
+	ret = dev_pm_opp_set_rate(mas->dev, sclk_freq);
  	if (ret)
-		dev_err(mas->dev, "clk_set_rate failed %d\n", ret);
+		dev_err(mas->dev, "dev_pm_opp_set_rate failed %d\n", ret);
  	return ret;
  }
 
@@ -553,6 +553,7 @@ static int spi_geni_probe(struct platform_device *pdev)
  	if (!spi)
  		return -ENOMEM;
 
Quoted 12 lines

drivers/spi/spi-geni-qcom.c static int spi_geni_probe(struct platform_device *pdev) · line 565

Quoted 9 lines
drivers/spi/spi-geni-qcom.c +2 -0
+
  	platform_set_drvdata(pdev, spi);
  	mas = spi_master_get_devdata(spi);
  	mas->irq = irq;
@@ -561,6 +562,8 @@ static int spi_geni_probe(struct platform_device *pdev)
  	mas->se.wrapper = dev_get_drvdata(dev->parent);
  	mas->se.base = base;
  	mas->se.clk = clk;
+	mas->se.opp = dev_pm_opp_set_clkname(&pdev->dev, "se");

As commented on the serial patch, it seems an error check is needed and the OPP table saved in 'struct geni_se' is never used.

right, I explained about the OPP table in the other patch.

Quoted 10 lines

drivers/spi/spi-geni-qcom.c static int spi_geni_probe(struct platform_device *pdev) · line 566

Quoted 2 lines
drivers/spi/spi-geni-qcom.c +1 -0
+	dev_pm_opp_of_add_table(&pdev->dev);

This function could also fail for multiple reasons, so the return value should be checked.

From patch "[01/21] opp: Manage empty OPP tables with clk handle" it seems
ignoring errors is intended to be able to operate when no OPP table is specified. But even with that you want to return in case of certain errors, like an invalid OPP table, out of memory or -EPROBE_DEFER.

Thats correct, my intention of not checking the errors was in cases where its optional, and I did not want to break anything with existing DT. I will go back and check if its indeed possible for it to return a -EPROBE_DEFER and others which I should handle.

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#14 lore raw

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

In reply to Akash Asthana

[]..

Quoted 36 lines
Quoted 24 lines
drivers/tty/serial/qcom_geni_serial.c +5 -2
@@ -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;
       }
       /*

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

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c +3 -1
@@ -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

Quoted 1 line

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

Quoted 2 lines

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

Quoted 2 lines
drivers/tty/serial/qcom_geni_serial.c +2 -0
+    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.

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#9 lore raw

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

In reply to Jun Nie
Quoted 8 lines · Jun Nie
Quoted 6 lines

drivers/tty/serial/qcom_geni_serial.c static void qcom_geni_serial_set_termios(struct uart_port *uport, · line 965

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c +1 -1
@@ -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);

Hi Rajendra,

Hi Jun,

Quoted 3 lines

I see lowest rpmhpd_opp_low_svs opp is for 75MHz. It is a bit higher for a serial.
I am just curious about this.

Well these OPP tables are technically what we call as fmax tables, which means you can get the clock to a max of 75MHz at that perf level. You need to go to the next perf level if you want to go higher.
That however does not mean that serial cannot run at clocks lower than 75Mhz.

Quoted 7 lines

I also want to confirm that the rpmhpd_opp_low_svs voltage restriction is for serial
controller, not for clock controller? Because I see there is similar restriction to clock
controller on another platform, the restriction is for branch clock, not leaf clock that
consumer device will get.

yes, its a serial controller restriction and not of the clock provider. On your note on the branch clock vs leaf clock I am not sure I understand the point you are making.

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#10 lore raw

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

Quoted 32 lines · Rajendra Nayak <[email protected]> 于2020年4月13日周一 下午10:22写道:
Quoted 8 lines · Jun Nie
Quoted 6 lines

drivers/tty/serial/qcom_geni_serial.c static void qcom_geni_serial_set_termios(struct uart_port *uport, · line 965

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c +1 -1
@@ -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);

Hi Rajendra,

Hi Jun,

Quoted 3 lines

I see lowest rpmhpd_opp_low_svs opp is for 75MHz. It is a bit higher for a serial.
I am just curious about this.

Well these OPP tables are technically what we call as fmax tables, which means you can get the clock to a max of 75MHz at that perf level. You need to go to the next perf level if you want to go higher.
That however does not mean that serial cannot run at clocks lower than 75Mhz.

Quoted 7 lines

I also want to confirm that the rpmhpd_opp_low_svs voltage restriction is for serial
controller, not for clock controller? Because I see there is similar restriction to clock
controller on another platform, the restriction is for branch clock, not leaf clock that
consumer device will get.

Quoted 3 lines

yes, its a serial controller restriction and not of the clock provider. On your note on the branch clock vs leaf clock I am not sure I understand the point you are making.

For the leaf clock, I mean the clock that consumer get with devm_clk_get(). The branch clock means it is not for consumer directly, and its child clock or grandchild
clock is for consumer. In that case, the restriction has to be done in clock driver,
not in clock consumer driver. Sorry for confusing you. I just want to know more about
what function this patch set provide. Because I am working on the clock controller
restriction of fmax/voltage. Thanks!

Jun

Quoted 4 lines

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

Applied
#5 lore raw

Re: [PATCH 01/21] opp: Manage empty OPP tables with clk handle

In reply to Rajendra Nayak
Quoted 9 lines · Rajendra Nayak

With OPP core now supporting DVFS for IO devices, we have instances of IO devices (same IP block) which require an OPP on some platforms/SoCs while just needing to scale the clock on some others.

In order to avoid conditional code in every driver which supports such devices (to check for availability of OPPs and then deciding to do either dev_pm_opp_set_rate() or clk_set_rate()) add support to manage empty OPP tables with a clk handle.

Quoted 8 lines

This makes dev_pm_opp_set_rate() equivalent of a clk_set_rate() for devices with just a clk and no OPPs specified, and makes dev_pm_opp_set_rate(0) bail out without throwing an error.

---
 drivers/opp/core.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Applied. Thanks.

Signature · 1 line
viresh
#28 lore raw

Re: [PATCH 13/21] mmc: sdhci-msm: Use OPP API to set clk/perf state

In reply to Rajendra Nayak
Quoted 7 lines · Rajendra Nayak

On some qualcomm SoCs we need to vote on a performance state of a power domain depending on the clock rates. Hence move to using OPP api to set the clock rate and performance state specified in the OPP table. On platforms without an OPP table, dev_pm_opp_set_rate() is eqvivalent to clk_set_rate()

Quoted 6 lines
Cc Ulf Hansson <[email protected]>
Cc Pradeep P V K <[email protected]>
Cc Veerabhadrarao Badiganti <[email protected]>
Cc Subhash Jadavani <[email protected]>

This looks good to me!

However, are there any of the other patches in the series that $subject patch depends on - or can I apply this as a standalone mmc patch?

Kind regards
Uffe

Quoted 103 lines
---
 drivers/mmc/host/sdhci-msm.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
drivers/mmc/host/sdhci-msm.c +16 -5
index 09ff731..d82075a 100644
@@ -10,6 +10,7 @@
 #include <linux/delay.h>
 #include <linux/mmc/mmc.h>
 #include <linux/pm_runtime.h>
+#include <linux/pm_opp.h>
 #include <linux/slab.h>
 #include <linux/iopoll.h>
 #include <linux/regulator/consumer.h>
@@ -242,6 +243,7 @@ struct sdhci_msm_host {
        struct clk *xo_clk;     /* TCXO clk needed for FLL feature of cm_dll*/
        struct clk_bulk_data bulk_clks[4]; /* core, iface, cal, sleep clocks */
        unsigned long clk_rate;
+       struct opp_table *opp;
        struct mmc_host *mmc;
        bool use_14lpp_dll_reset;
        bool tuning_done;
@@ -332,7 +334,7 @@ static void msm_set_clock_rate_for_bus_mode(struct sdhci_host *host,
        int rc;
 
        clock = msm_get_clock_rate_for_bus_mode(host, clock);
-       rc = clk_set_rate(core_clk, clock);
+       rc = dev_pm_opp_set_rate(mmc_dev(host->mmc), clock);
        if (rc) {
                pr_err("%s: Failed to set clock at rate %u at timing %d\n",
                       mmc_hostname(host->mmc), clock,
@@ -1963,7 +1965,7 @@ static int sdhci_msm_probe(struct platform_device *pdev)
        msm_host->bulk_clks[0].clk = clk;
 
        /* Vote for maximum clock rate for maximum performance */
-       ret = clk_set_rate(clk, INT_MAX);
+       ret = dev_pm_opp_set_rate(&pdev->dev, INT_MAX);
        if (ret)
                dev_warn(&pdev->dev, "core clock boost failed\n");
 
@@ -2087,6 +2089,9 @@ static int sdhci_msm_probe(struct platform_device *pdev)
                goto clk_disable;
        }
 
+       msm_host->opp = dev_pm_opp_set_clkname(&pdev->dev, "core");
+       dev_pm_opp_of_add_table(&pdev->dev);
+
        pm_runtime_get_noresume(&pdev->dev);
        pm_runtime_set_active(&pdev->dev);
        pm_runtime_enable(&pdev->dev);
@@ -2109,10 +2114,12 @@ static int sdhci_msm_probe(struct platform_device *pdev)
        return 0;
 
 pm_runtime_disable:
+       dev_pm_opp_of_remove_table(&pdev->dev);
        pm_runtime_disable(&pdev->dev);
        pm_runtime_set_suspended(&pdev->dev);
        pm_runtime_put_noidle(&pdev->dev);
 clk_disable:
+       dev_pm_opp_set_rate(&pdev->dev, 0);
        clk_bulk_disable_unprepare(ARRAY_SIZE(msm_host->bulk_clks),
                                   msm_host->bulk_clks);
 bus_clk_disable:
@@ -2133,10 +2140,12 @@ static int sdhci_msm_remove(struct platform_device *pdev)
 
        sdhci_remove_host(host, dead);
 
+       dev_pm_opp_of_remove_table(&pdev->dev);
        pm_runtime_get_sync(&pdev->dev);
        pm_runtime_disable(&pdev->dev);
        pm_runtime_put_noidle(&pdev->dev);
 
+       dev_pm_opp_set_rate(&pdev->dev, 0);
        clk_bulk_disable_unprepare(ARRAY_SIZE(msm_host->bulk_clks),
                                   msm_host->bulk_clks);
        if (!IS_ERR(msm_host->bus_clk))
@@ -2151,6 +2160,7 @@ static __maybe_unused int sdhci_msm_runtime_suspend(struct device *dev)
        struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
        struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
 
+       dev_pm_opp_set_rate(dev, 0);
        clk_bulk_disable_unprepare(ARRAY_SIZE(msm_host->bulk_clks),
                                   msm_host->bulk_clks);
 
@@ -2173,9 +2183,11 @@ static __maybe_unused int sdhci_msm_runtime_resume(struct device *dev)
         * restore the SDR DLL settings when the clock is ungated.
         */
        if (msm_host->restore_dll_config && msm_host->clk_rate)
-               return sdhci_msm_restore_sdr_dll_config(host);
+               ret = sdhci_msm_restore_sdr_dll_config(host);
 
-       return 0;
+       dev_pm_opp_set_rate(dev, msm_host->clk_rate);
+
+       return ret;
 }
 
 static const struct dev_pm_ops sdhci_msm_pm_ops = {
--

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

#29 lore raw

Re: [PATCH 13/21] mmc: sdhci-msm: Use OPP API to set clk/perf state

Quoted 15 lines · Ulf Hansson
Quoted 7 lines · Rajendra Nayak

On some qualcomm SoCs we need to vote on a performance state of a power domain depending on the clock rates. Hence move to using OPP api to set the clock rate and performance state specified in the OPP table. On platforms without an OPP table, dev_pm_opp_set_rate() is eqvivalent to clk_set_rate()

Quoted 6 lines
Cc Ulf Hansson <[email protected]>
Cc Pradeep P V K <[email protected]>
Cc Veerabhadrarao Badiganti <[email protected]>
Cc Subhash Jadavani <[email protected]>
Quoted 5 lines

This looks good to me!

However, are there any of the other patches in the series that $subject patch depends on - or can I apply this as a standalone mmc patch?

Hey Ulf, thanks for the review. I'll just need to respin these to make sure I do not do a dev_pm_opp_of_remove_table() if dev_pm_opp_of_add_table() isn;t successful as discussed with Viresh on another thread [1]

As for the dependencies, its only PATCH 01/21 in this series and that's already been queued by Viresh [2]

[1] https://lkml.org/lkml/2020/4/15/18
[2] https://lkml.org/lkml/2020/4/14/98

Quoted 107 lines

Kind regards
Uffe

Quoted 103 lines
---
  drivers/mmc/host/sdhci-msm.c | 20 ++++++++++++++++----
  1 file changed, 16 insertions(+), 4 deletions(-)
drivers/mmc/host/sdhci-msm.c +16 -5
index 09ff731..d82075a 100644
@@ -10,6 +10,7 @@
  #include <linux/delay.h>
  #include <linux/mmc/mmc.h>
  #include <linux/pm_runtime.h>
+#include <linux/pm_opp.h>
  #include <linux/slab.h>
  #include <linux/iopoll.h>
  #include <linux/regulator/consumer.h>
@@ -242,6 +243,7 @@ struct sdhci_msm_host {
         struct clk *xo_clk;     /* TCXO clk needed for FLL feature of cm_dll*/
         struct clk_bulk_data bulk_clks[4]; /* core, iface, cal, sleep clocks */
         unsigned long clk_rate;
+       struct opp_table *opp;
         struct mmc_host *mmc;
         bool use_14lpp_dll_reset;
         bool tuning_done;
@@ -332,7 +334,7 @@ static void msm_set_clock_rate_for_bus_mode(struct sdhci_host *host,
         int rc;
 
         clock = msm_get_clock_rate_for_bus_mode(host, clock);
-       rc = clk_set_rate(core_clk, clock);
+       rc = dev_pm_opp_set_rate(mmc_dev(host->mmc), clock);
         if (rc) {
                 pr_err("%s: Failed to set clock at rate %u at timing %d\n",
                        mmc_hostname(host->mmc), clock,
@@ -1963,7 +1965,7 @@ static int sdhci_msm_probe(struct platform_device *pdev)
         msm_host->bulk_clks[0].clk = clk;
 
         /* Vote for maximum clock rate for maximum performance */
-       ret = clk_set_rate(clk, INT_MAX);
+       ret = dev_pm_opp_set_rate(&pdev->dev, INT_MAX);
         if (ret)
                 dev_warn(&pdev->dev, "core clock boost failed\n");
 
@@ -2087,6 +2089,9 @@ static int sdhci_msm_probe(struct platform_device *pdev)
                 goto clk_disable;
         }
 
+       msm_host->opp = dev_pm_opp_set_clkname(&pdev->dev, "core");
+       dev_pm_opp_of_add_table(&pdev->dev);
+
         pm_runtime_get_noresume(&pdev->dev);
         pm_runtime_set_active(&pdev->dev);
         pm_runtime_enable(&pdev->dev);
@@ -2109,10 +2114,12 @@ static int sdhci_msm_probe(struct platform_device *pdev)
         return 0;
 
  pm_runtime_disable:
+       dev_pm_opp_of_remove_table(&pdev->dev);
         pm_runtime_disable(&pdev->dev);
         pm_runtime_set_suspended(&pdev->dev);
         pm_runtime_put_noidle(&pdev->dev);
  clk_disable:
+       dev_pm_opp_set_rate(&pdev->dev, 0);
         clk_bulk_disable_unprepare(ARRAY_SIZE(msm_host->bulk_clks),
                                    msm_host->bulk_clks);
  bus_clk_disable:
@@ -2133,10 +2140,12 @@ static int sdhci_msm_remove(struct platform_device *pdev)
 
         sdhci_remove_host(host, dead);
 
+       dev_pm_opp_of_remove_table(&pdev->dev);
         pm_runtime_get_sync(&pdev->dev);
         pm_runtime_disable(&pdev->dev);
         pm_runtime_put_noidle(&pdev->dev);
 
+       dev_pm_opp_set_rate(&pdev->dev, 0);
         clk_bulk_disable_unprepare(ARRAY_SIZE(msm_host->bulk_clks),
                                    msm_host->bulk_clks);
         if (!IS_ERR(msm_host->bus_clk))
@@ -2151,6 +2160,7 @@ static __maybe_unused int sdhci_msm_runtime_suspend(struct device *dev)
         struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
         struct sdhci_msm_host *msm_host = sdhci_pltfm_priv(pltfm_host);
 
+       dev_pm_opp_set_rate(dev, 0);
         clk_bulk_disable_unprepare(ARRAY_SIZE(msm_host->bulk_clks),
                                    msm_host->bulk_clks);
 
@@ -2173,9 +2183,11 @@ static __maybe_unused int sdhci_msm_runtime_resume(struct device *dev)
          * restore the SDR DLL settings when the clock is ungated.
          */
         if (msm_host->restore_dll_config && msm_host->clk_rate)
-               return sdhci_msm_restore_sdr_dll_config(host);
+               ret = sdhci_msm_restore_sdr_dll_config(host);
 
-       return 0;
+       dev_pm_opp_set_rate(dev, msm_host->clk_rate);
+
+       return ret;
  }
 
  static const struct dev_pm_ops sdhci_msm_pm_ops = {
--

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

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#30 lore raw

Re: [PATCH 13/21] mmc: sdhci-msm: Use OPP API to set clk/perf state

Quoted 2 lines · Rajendra Nayak

As for the dependencies, its only PATCH 01/21 in this series and that's already been queued by Viresh [2]

It must be part of v5.7-rc2

Signature · 1 line
viresh
#31 lore raw

Re: [PATCH 13/21] mmc: sdhci-msm: Use OPP API to set clk/perf state

Quoted 6 lines · Viresh Kumar
Quoted 2 lines · Rajendra Nayak

As for the dependencies, its only PATCH 01/21 in this series and that's already been queued by Viresh [2]

It must be part of v5.7-rc2

Great, thanks!

KInd regards
Uffe

#32 lore raw

Re: [PATCH 13/21] mmc: sdhci-msm: Use OPP API to set clk/perf state

In reply to Rajendra Nayak
Quoted 25 lines · Rajendra Nayak
Quoted 15 lines · Ulf Hansson
Quoted 7 lines · Rajendra Nayak

On some qualcomm SoCs we need to vote on a performance state of a power domain depending on the clock rates. Hence move to using OPP api to set the clock rate and performance state specified in the OPP table. On platforms without an OPP table, dev_pm_opp_set_rate() is eqvivalent to clk_set_rate()

Quoted 6 lines
Cc Ulf Hansson <[email protected]>
Cc Pradeep P V K <[email protected]>
Cc Veerabhadrarao Badiganti <[email protected]>
Cc Subhash Jadavani <[email protected]>
Quoted 5 lines

This looks good to me!

However, are there any of the other patches in the series that $subject patch depends on - or can I apply this as a standalone mmc patch?

Quoted 6 lines

Hey Ulf, thanks for the review. I'll just need to respin these to make sure I do not do a dev_pm_opp_of_remove_table() if dev_pm_opp_of_add_table() isn;t successful as discussed with Viresh on another thread [1]

As for the dependencies, its only PATCH 01/21 in this series and that's already been queued by Viresh [2]

I see, thanks!

Looks like Viresh is sending it to be included for v5.7-rc2, so I can pick your new version of $subject patch next week.

[...]

Kind regards
Uffe