[PATCH v1 03/12] soc: qcom: geni-se: Introduce helper API for resource initialization

Praveen Talari posted 12 patches 1 week, 2 days ago
[PATCH v1 03/12] soc: qcom: geni-se: Introduce helper API for resource initialization
Posted by Praveen Talari 1 week, 2 days ago
The GENI Serial Engine drivers (I2C, SPI, and SERIAL) currently duplicate
code for initializing shared resources such as clocks and interconnect
paths.

Introduce a new helper API, geni_se_resources_init(), to centralize this
initialization logic, improving modularity and simplifying the probe
function.

Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com>
---
 drivers/soc/qcom/qcom-geni-se.c  | 47 ++++++++++++++++++++++++++++++++
 include/linux/soc/qcom/geni-se.h |  6 ++++
 2 files changed, 53 insertions(+)

diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c
index b0542f836453..726b77650007 100644
--- a/drivers/soc/qcom/qcom-geni-se.c
+++ b/drivers/soc/qcom/qcom-geni-se.c
@@ -19,6 +19,7 @@
 #include <linux/of_platform.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/platform_device.h>
+#include <linux/pm_opp.h>
 #include <linux/soc/qcom/geni-se.h>
 
 /**
@@ -1012,6 +1013,52 @@ int geni_icc_disable(struct geni_se *se)
 }
 EXPORT_SYMBOL_GPL(geni_icc_disable);
 
+/**
+ * geni_se_resources_init() - Initialize resources for a GENI SE device.
+ * @se: Pointer to the geni_se structure representing the GENI SE device.
+ *
+ * This function initializes various resources required by the GENI Serial Engine
+ * (SE) device, including clock resources (core and SE clocks), interconnect
+ * paths for communication.
+ * It retrieves optional and mandatory clock resources, adds an OF-based
+ * operating performance point (OPP) table, and sets up interconnect paths
+ * with default bandwidths. The function also sets a flag (`has_opp`) to
+ * indicate whether OPP support is available for the device.
+ *
+ * Return: 0 on success, or a negative errno on failure.
+ */
+int geni_se_resources_init(struct geni_se *se)
+{
+	int ret;
+
+	se->core_clk = devm_clk_get_optional(se->dev, "core");
+	if (IS_ERR(se->core_clk))
+		return dev_err_probe(se->dev, PTR_ERR(se->core_clk),
+				     "Failed to get optional core clk\n");
+
+	se->clk = devm_clk_get(se->dev, "se");
+	if (IS_ERR(se->clk) && !has_acpi_companion(se->dev))
+		return dev_err_probe(se->dev, PTR_ERR(se->clk),
+				     "Failed to get SE clk\n");
+
+	ret = devm_pm_opp_set_clkname(se->dev, "se");
+	if (ret)
+		return ERR_PTR(ret);
+
+	ret = devm_pm_opp_of_add_table(se->dev);
+	if (ret && ret != -ENODEV)
+		return dev_err_probe(se->dev, ret, "Failed to add OPP table\n");
+
+	se->has_opp = (ret == 0);
+
+	ret = geni_icc_get(se, "qup-memory");
+	if (ret)
+		return ret;
+
+	return geni_icc_set_bw_ab(se, GENI_DEFAULT_BW, GENI_DEFAULT_BW, GENI_DEFAULT_BW);
+}
+EXPORT_SYMBOL_GPL(geni_se_resources_init);
+
 /**
  * geni_find_protocol_fw() - Locate and validate SE firmware for a protocol.
  * @dev: Pointer to the device structure.
diff --git a/include/linux/soc/qcom/geni-se.h b/include/linux/soc/qcom/geni-se.h
index 980aabea2157..c182dd0f0bde 100644
--- a/include/linux/soc/qcom/geni-se.h
+++ b/include/linux/soc/qcom/geni-se.h
@@ -60,18 +60,22 @@ struct geni_icc_path {
  * @dev:		Pointer to the Serial Engine device
  * @wrapper:		Pointer to the parent QUP Wrapper core
  * @clk:		Handle to the core serial engine clock
+ * @core_clk:		Auxiliary clock, which may be required by a protocol
  * @num_clk_levels:	Number of valid clock levels in clk_perf_tbl
  * @clk_perf_tbl:	Table of clock frequency input to serial engine clock
  * @icc_paths:		Array of ICC paths for SE
+ * @has_opp:		Indicates if OPP is supported
  */
 struct geni_se {
 	void __iomem *base;
 	struct device *dev;
 	struct geni_wrapper *wrapper;
 	struct clk *clk;
+	struct clk *core_clk;
 	unsigned int num_clk_levels;
 	unsigned long *clk_perf_tbl;
 	struct geni_icc_path icc_paths[3];
+	bool has_opp;
 };
 
 /* Common SE registers */
@@ -535,6 +539,8 @@ int geni_icc_enable(struct geni_se *se);
 
 int geni_icc_disable(struct geni_se *se);
 
+int geni_se_resources_init(struct geni_se *se);
+
 int geni_load_se_firmware(struct geni_se *se, enum geni_se_protocol_type protocol);
 #endif
 #endif
-- 
2.34.1
Re: [PATCH v1 03/12] soc: qcom: geni-se: Introduce helper API for resource initialization
Posted by kernel test robot 1 week, 1 day ago
Hi Praveen,

kernel test robot noticed the following build errors:

[auto build test ERROR on d724c6f85e80a23ed46b7ebc6e38b527c09d64f5]

url:    https://github.com/intel-lab-lkp/linux/commits/Praveen-Talari/soc-qcom-geni-se-Refactor-geni_icc_get-and-make-qup-memory-ICC-path-optional/20251122-130449
base:   d724c6f85e80a23ed46b7ebc6e38b527c09d64f5
patch link:    https://lore.kernel.org/r/20251122050018.283669-4-praveen.talari%40oss.qualcomm.com
patch subject: [PATCH v1 03/12] soc: qcom: geni-se: Introduce helper API for resource initialization
config: loongarch-randconfig-002-20251123 (https://download.01.org/0day-ci/archive/20251123/202511231819.jiLYo6Fl-lkp@intel.com/config)
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251123/202511231819.jiLYo6Fl-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202511231819.jiLYo6Fl-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/soc/qcom/qcom-geni-se.c:1046:10: error: incompatible pointer to integer conversion returning 'void *' from a function with result type 'int' [-Wint-conversion]
    1046 |                 return ERR_PTR(ret);
         |                        ^~~~~~~~~~~~
   1 error generated.


vim +1046 drivers/soc/qcom/qcom-geni-se.c

  1015	
  1016	/**
  1017	 * geni_se_resources_init() - Initialize resources for a GENI SE device.
  1018	 * @se: Pointer to the geni_se structure representing the GENI SE device.
  1019	 *
  1020	 * This function initializes various resources required by the GENI Serial Engine
  1021	 * (SE) device, including clock resources (core and SE clocks), interconnect
  1022	 * paths for communication.
  1023	 * It retrieves optional and mandatory clock resources, adds an OF-based
  1024	 * operating performance point (OPP) table, and sets up interconnect paths
  1025	 * with default bandwidths. The function also sets a flag (`has_opp`) to
  1026	 * indicate whether OPP support is available for the device.
  1027	 *
  1028	 * Return: 0 on success, or a negative errno on failure.
  1029	 */
  1030	int geni_se_resources_init(struct geni_se *se)
  1031	{
  1032		int ret;
  1033	
  1034		se->core_clk = devm_clk_get_optional(se->dev, "core");
  1035		if (IS_ERR(se->core_clk))
  1036			return dev_err_probe(se->dev, PTR_ERR(se->core_clk),
  1037					     "Failed to get optional core clk\n");
  1038	
  1039		se->clk = devm_clk_get(se->dev, "se");
  1040		if (IS_ERR(se->clk) && !has_acpi_companion(se->dev))
  1041			return dev_err_probe(se->dev, PTR_ERR(se->clk),
  1042					     "Failed to get SE clk\n");
  1043	
  1044		ret = devm_pm_opp_set_clkname(se->dev, "se");
  1045		if (ret)
> 1046			return ERR_PTR(ret);
  1047	
  1048		ret = devm_pm_opp_of_add_table(se->dev);
  1049		if (ret && ret != -ENODEV)
  1050			return dev_err_probe(se->dev, ret, "Failed to add OPP table\n");
  1051	
  1052		se->has_opp = (ret == 0);
  1053	
  1054		ret = geni_icc_get(se, "qup-memory");
  1055		if (ret)
  1056			return ret;
  1057	
  1058		return geni_icc_set_bw_ab(se, GENI_DEFAULT_BW, GENI_DEFAULT_BW, GENI_DEFAULT_BW);
  1059	}
  1060	EXPORT_SYMBOL_GPL(geni_se_resources_init);
  1061	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki