Expose an API to read the current Serdes Port mode. This is needed for pheriperal attached to the Serdes mode to validate the Serdes port is in the correct mode. Each driver will have to define in DT the phandle airoha,scu pointing to the SCU node to make use of this API. Function airoha_scu_ssr_get_serdes_mode() will then parse the phandle, and extract tha Serdes Port state from the SCU SSR driver priv. Driver will use the new API airoha_scu_ssr_get_serdes_mode() by passing the dev and the serdes mode reference from dt-bindings header. Signed-off-by: Christian Marangi <ansuelsmth@xxxxxxxxx> --- drivers/soc/airoha/airoha-scu-ssr.c | 50 +++++++++++++++++++++++ include/linux/soc/airoha/airoha-scu-ssr.h | 11 +++++ 2 files changed, 61 insertions(+) diff --git a/drivers/soc/airoha/airoha-scu-ssr.c b/drivers/soc/airoha/airoha-scu-ssr.c index 29e17577e9a4..3fbc36f793d0 100644 --- a/drivers/soc/airoha/airoha-scu-ssr.c +++ b/drivers/soc/airoha/airoha-scu-ssr.c @@ -5,6 +5,7 @@ #include <dt-bindings/soc/airoha,scu-ssr.h> #include <linux/bitfield.h> +#include <linux/clk/clk-en7523.h> #include <linux/of.h> #include <linux/of_platform.h> #include <linux/platform_device.h> @@ -54,6 +55,55 @@ static int airoha_scu_serdes_str_to_mode(const char *serdes_str) return -EINVAL; } +/** + * airoha_scu_ssr_get_serdes_mode - Get current Mode for Serdes Port + * @dev: Device pointer of the Serdes Port peripheral + * @port: Reference number of the Serdes Port + * + * Parse the phandle pointed by the Device Node property + * "airoha,scu" present in Devide Node of dev and get + * the current Mode of the Serdes Port reference by port + * + * Return the mode or a negative error code. If the pdev + * or the driver data for the SCU can't be found, + * -EPROBE_DEFER is returned. + */ +int airoha_scu_ssr_get_serdes_mode(struct device *dev, + unsigned int port) +{ + struct airoha_scu_ssr_priv *priv; + struct en_clk_priv *clk_priv; + struct platform_device *pdev; + struct device_node *np; + + np = of_parse_phandle(dev->of_node, "airoha,scu", 0); + if (!np) + return -ENODEV; + + if (!of_device_is_available(np)) { + of_node_put(np); + return -ENODEV; + } + + pdev = of_find_device_by_node(np); + of_node_put(np); + if (!pdev || !platform_get_drvdata(pdev)) { + if (pdev) + put_device(&pdev->dev); + return -EPROBE_DEFER; + } + + /* + * Get pdev from clk priv. Clock driver register + * SSR driver hence it can be assumed present. + */ + clk_priv = platform_get_drvdata(pdev); + priv = platform_get_drvdata(clk_priv->ssr_pdev); + + return priv->serdes_port[port]; +} +EXPORT_SYMBOL_GPL(airoha_scu_ssr_get_serdes_mode); + static int airoha_scu_ssr_apply_modes(struct airoha_scu_ssr_priv *priv) { int ret; diff --git a/include/linux/soc/airoha/airoha-scu-ssr.h b/include/linux/soc/airoha/airoha-scu-ssr.h index 0224c0340b6d..81f2c1b57889 100644 --- a/include/linux/soc/airoha/airoha-scu-ssr.h +++ b/include/linux/soc/airoha/airoha-scu-ssr.h @@ -20,4 +20,15 @@ struct airoha_scu_ssr_data { const struct airoha_scu_ssr_serdes_info *ports_info; }; +#if IS_ENABLED(CONFIG_AIROHA_SCU_SSR) +int airoha_scu_ssr_get_serdes_mode(struct device *dev, + unsigned int port); +#else +static inline int airoha_scu_ssr_get_serdes_mode(struct device *dev, + unsigned int port); +{ + return -EOPNOTSUPP; +} +#endif + #endif -- 2.48.1