drivers: Defer probe if firmware is not ready
Subsystems (7)
PATCH 1/1 drivers: Defer probe if firmware is not ready
From: Rajan Vaja <[email protected]>
Driver needs ZynqMP firmware interface to call EEMI APIs. In case firmware is not ready, dependent drivers should wait until the firmware is ready.
Signed-off-by Rajan Vaja <[email protected]>
Signed-off-by Jolly Shah <[email protected]>
--- Documentation/xilinx/eemi.txt | 4 ++-- drivers/clk/zynqmp/clkc.c | 4 ++-- drivers/firmware/xilinx/zynqmp-debug.c | 3 --- drivers/firmware/xilinx/zynqmp.c | 11 ++++++++++- drivers/nvmem/zynqmp_nvmem.c | 10 +++++++--- drivers/reset/reset-zynqmp.c | 8 ++++---- drivers/soc/xilinx/zynqmp_pm_domains.c | 18 ++++++++++-------- drivers/soc/xilinx/zynqmp_power.c | 10 ++++++---- drivers/spi/spi-zynqmp-gqspi.c | 5 +++++ include/linux/firmware/xlnx-zynqmp.h | 2 +- 10 files changed, 47 insertions(+), 28 deletions(-)
Documentation/xilinx/eemi.txt +2 -2
@@ -41,8 +41,8 @@ Example of EEMI ops usage: int ret; eemi_ops = zynqmp_pm_get_eemi_ops(); - if (!eemi_ops) - return -ENXIO; + if (IS_ERR(eemi_ops)) + return PTR_ERR(eemi_ops); ret = eemi_ops->query_data(qdata, ret_payload);
drivers/clk/zynqmp/clkc.c +2 -2
@@ -711,8 +711,8 @@ static int zynqmp_clock_probe(struct platform_device *pdev)struct device *dev = &pdev->dev; eemi_ops =zynqmp_pm_get_eemi_ops (); -if (!eemi_ops) -return -ENXIO ; +if (IS_ERR (eemi_ops)) +return PTR_ERR (eemi_ops); ret =zynqmp_clk_setup (dev->of_node);
drivers/firmware/xilinx/zynqmp-debug.c +0 -3
@@ -90,9 +90,6 @@ static int process_api_request(u32 pm_id, u64 *pm_api_arg, u32 *pm_api_ret)int ret;struct zynqmp_pm_query_data qdata = {0 }; -if (!eemi_ops) -return -ENXIO ; -switch (pm_id) {case PM_GET_API_VERSION : ret = eemi_ops->get_api_version (&pm_api_version);
drivers/firmware/xilinx/zynqmp.c +10 -1
@@ -24,6 +24,8 @@#include <linux/firmware/xlnx-zynqmp.h> #include "zynqmp-debug.h" +static const struct zynqmp_eemi_ops *eemi_ops_tbl; +static const struct mfd_cell firmware_devs[] = { { .name ="zynqmp_power_controller" ,
@@ -649,7 +651,11 @@ static const struct zynqmp_eemi_ops eemi_ops = {*/ const struct zynqmp_eemi_ops *zynqmp_pm_get_eemi_ops (void ) { -return &eemi_ops; +if (eemi_ops_tbl) +return eemi_ops_tbl; +else +return ERR_PTR (-EPROBE_DEFER ); + }EXPORT_SYMBOL_GPL (zynqmp_pm_get_eemi_ops);
@@ -694,6 +700,9 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)pr_info ("%s Trustzone version v%d.%d\n" , __func__, pm_tz_version >>16 , pm_tz_version &0xFFFF ); +/* Assign eemi_ops_table */ + eemi_ops_tbl = &eemi_ops; +zynqmp_pm_api_debugfs_init (); ret = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, firmware_devs,
drivers/nvmem/zynqmp_nvmem.c +7 -3
@@ -16,6 +16,8 @@ struct zynqmp_nvmem_data {struct nvmem_device *nvmem; }; +static const struct zynqmp_eemi_ops *eemi_ops; +static int zynqmp_nvmem_read (void *context,unsigned int offset,void *val,size_t bytes) {
@@ -23,9 +25,7 @@ static int zynqmp_nvmem_read(void *context, unsigned int offset,int idcode, version;struct zynqmp_nvmem_data *priv = context; -const struct zynqmp_eemi_ops *eemi_ops =zynqmp_pm_get_eemi_ops (); - -if (!eemi_ops || !eemi_ops->get_chipid) +if (!eemi_ops->get_chipid)return -ENXIO ; ret = eemi_ops->get_chipid (&idcode, &version);
@@ -61,6 +61,10 @@ static int zynqmp_nvmem_probe(struct platform_device *pdev)if (!priv)return -ENOMEM ; + eemi_ops =zynqmp_pm_get_eemi_ops (); +if (IS_ERR (eemi_ops)) +return PTR_ERR (eemi_ops); + priv->dev = dev; econfig.dev = dev; econfig.reg_read = zynqmp_nvmem_read;
drivers/reset/reset-zynqmp.c +4 -4
@@ -79,11 +79,11 @@ static int zynqmp_reset_probe(struct platform_device *pdev)if (!priv)return -ENOMEM ; -platform_set_drvdata (pdev, priv); - priv->eemi_ops =zynqmp_pm_get_eemi_ops (); -if (!priv->eemi_ops) -return -ENXIO ; +if (IS_ERR (priv->eemi_ops)) +return PTR_ERR (priv->eemi_ops); + +platform_set_drvdata (pdev, priv); priv->rcdev.ops = &zynqmp_reset_ops; priv->rcdev.owner =THIS_MODULE ;
drivers/soc/xilinx/zynqmp_pm_domains.c +10 -8
@@ -23,6 +23,8 @@/* Flag stating if PM nodes mapped to the PM domain has been requested */ #define ZYNQMP_PM_DOMAIN_REQUESTED BIT(0) +static const struct zynqmp_eemi_ops *eemi_ops; +/** * struct zynqmp_pm_domain - Wrapper around struct generic_pm_domain * @gpd: Generic power domain
@@ -71,9 +73,8 @@ static int zynqmp_gpd_power_on(struct generic_pm_domain *domain) {int ret;struct zynqmp_pm_domain *pd; -const struct zynqmp_eemi_ops *eemi_ops =zynqmp_pm_get_eemi_ops (); -if (!eemi_ops || !eemi_ops->set_requirement) +if (!eemi_ops->set_requirement)return -ENXIO ; pd = container_of(domain, struct zynqmp_pm_domain, gpd);
@@ -107,9 +108,8 @@ static int zynqmp_gpd_power_off(struct generic_pm_domain *domain)struct zynqmp_pm_domain *pd;u32 capabilities =0 ;bool may_wakeup; -const struct zynqmp_eemi_ops *eemi_ops =zynqmp_pm_get_eemi_ops (); -if (!eemi_ops || !eemi_ops->set_requirement) +if (!eemi_ops->set_requirement)return -ENXIO ; pd = container_of(domain, struct zynqmp_pm_domain, gpd);
@@ -160,9 +160,8 @@ static int zynqmp_gpd_attach_dev(struct generic_pm_domain *domain, {int ret;struct zynqmp_pm_domain *pd; -const struct zynqmp_eemi_ops *eemi_ops =zynqmp_pm_get_eemi_ops (); -if (!eemi_ops || !eemi_ops->request_node) +if (!eemi_ops->request_node)return -ENXIO ; pd = container_of(domain, struct zynqmp_pm_domain, gpd);
@@ -197,9 +196,8 @@ static void zynqmp_gpd_detach_dev(struct generic_pm_domain *domain, {int ret;struct zynqmp_pm_domain *pd; -const struct zynqmp_eemi_ops *eemi_ops =zynqmp_pm_get_eemi_ops (); -if (!eemi_ops || !eemi_ops->release_node) +if (!eemi_ops->release_node)return ; pd = container_of(domain, struct zynqmp_pm_domain, gpd);
@@ -266,6 +264,10 @@ static int zynqmp_gpd_probe(struct platform_device *pdev)struct zynqmp_pm_domain *pd;struct device *dev = &pdev->dev; + eemi_ops =zynqmp_pm_get_eemi_ops (); +if (IS_ERR (eemi_ops)) +return PTR_ERR (eemi_ops); + pd =devm_kcalloc (dev,ZYNQMP_NUM_DOMAINS ,sizeof (*pd),GFP_KERNEL );if (!pd)return -ENOMEM ;
drivers/soc/xilinx/zynqmp_power.c +6 -4
@@ -31,6 +31,7 @@ static const char *const suspend_modes[] = { };static enum pm_suspend_mode suspend_mode =PM_SUSPEND_MODE_STD ; +static const struct zynqmp_eemi_ops *eemi_ops;enum pm_api_cb_id {PM_INIT_SUSPEND_CB =30 ,
@@ -92,9 +93,8 @@ static ssize_t suspend_mode_store(struct device *dev, const char *buf, size_t count) { int md, ret = -EINVAL; -const struct zynqmp_eemi_ops *eemi_ops =zynqmp_pm_get_eemi_ops (); -if (!eemi_ops || !eemi_ops->set_suspend_mode) +if (!eemi_ops->set_suspend_mode)return ret;for (md =PM_SUSPEND_MODE_FIRST ; md <ARRAY_SIZE (suspend_modes); md++)
@@ -120,9 +120,11 @@ static int zynqmp_pm_probe(struct platform_device *pdev)int ret, irq;u32 pm_api_version; -const struct zynqmp_eemi_ops *eemi_ops =zynqmp_pm_get_eemi_ops (); + eemi_ops =zynqmp_pm_get_eemi_ops (); +if (IS_ERR (eemi_ops)) +return PTR_ERR (eemi_ops); -if (!eemi_ops || !eemi_ops->get_api_version || !eemi_ops->init_finalize) +if (!eemi_ops->get_api_version || !eemi_ops->init_finalize)return -ENXIO ; eemi_ops->init_finalize ();
drivers/spi/spi-zynqmp-gqspi.c +5 -0
@@ -138,6 +138,7 @@#define SPI_AUTOSUSPEND_TIMEOUT 3000enum mode_type {GQSPI_MODE_IO ,GQSPI_MODE_DMA }; +static const struct zynqmp_eemi_ops *eemi_ops;/** * struct zynqmp_qspi - Defines qspi driver instance
@@ -1021,6 +1022,10 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)struct resource *res;struct device *dev = &pdev->dev; + eemi_ops =zynqmp_pm_get_eemi_ops (); +if (IS_ERR (eemi_ops)) +return PTR_ERR (eemi_ops); + master =spi_alloc_master (&pdev->dev,sizeof (*xqspi));if (!master)return -ENOMEM ;
include/linux/firmware/xlnx-zynqmp.h +1 -1
@@ -293,7 +293,7 @@ const struct zynqmp_eemi_ops *zynqmp_pm_get_eemi_ops(void);#else static inline struct zynqmp_eemi_ops *zynqmp_pm_get_eemi_ops (void ) { -return NULL ; +return ERR_PTR (-ENODEV ); }#endif
Signature · 1 line
2.7.4
Michal Simek
AppliedQuoted 290 lines · Jolly Shah
From: Rajan Vaja <[email protected]>
Driver needs ZynqMP firmware interface to call EEMI APIs. In case firmware is not ready, dependent drivers should wait until the firmware is ready.
Signed-off-by Rajan Vaja <[email protected]>Signed-off-by Jolly Shah <[email protected]>--- Documentation/xilinx/eemi.txt | 4 ++-- drivers/clk/zynqmp/clkc.c | 4 ++-- drivers/firmware/xilinx/zynqmp-debug.c | 3 --- drivers/firmware/xilinx/zynqmp.c | 11 ++++++++++- drivers/nvmem/zynqmp_nvmem.c | 10 +++++++--- drivers/reset/reset-zynqmp.c | 8 ++++---- drivers/soc/xilinx/zynqmp_pm_domains.c | 18 ++++++++++-------- drivers/soc/xilinx/zynqmp_power.c | 10 ++++++---- drivers/spi/spi-zynqmp-gqspi.c | 5 +++++ include/linux/firmware/xlnx-zynqmp.h | 2 +- 10 files changed, 47 insertions(+), 28 deletions(-)Documentation/xilinx/eemi.txt +2
-2@@ -41,8 +41,8 @@ Example of EEMI ops usage: int ret; eemi_ops = zynqmp_pm_get_eemi_ops(); - if (!eemi_ops) - return -ENXIO; + if (IS_ERR(eemi_ops)) + return PTR_ERR(eemi_ops); ret = eemi_ops->query_data(qdata, ret_payload);drivers/clk/zynqmp/clkc.c +2
-2@@ -711,8 +711,8 @@ static int zynqmp_clock_probe(struct platform_device *pdev)struct device *dev = &pdev->dev; eemi_ops =zynqmp_pm_get_eemi_ops (); -if (!eemi_ops) -return -ENXIO ; +if (IS_ERR (eemi_ops)) +return PTR_ERR (eemi_ops); ret =zynqmp_clk_setup (dev->of_node);drivers/firmware/xilinx/zynqmp-debug.c +0
-3@@ -90,9 +90,6 @@ static int process_api_request(u32 pm_id, u64 *pm_api_arg, u32 *pm_api_ret)int ret;struct zynqmp_pm_query_data qdata = {0 }; -if (!eemi_ops) -return -ENXIO ; -switch (pm_id) {case PM_GET_API_VERSION : ret = eemi_ops->get_api_version (&pm_api_version);drivers/firmware/xilinx/zynqmp.c +10
-1@@ -24,6 +24,8 @@#include <linux/firmware/xlnx-zynqmp.h> #include "zynqmp-debug.h" +static const struct zynqmp_eemi_ops *eemi_ops_tbl; +static const struct mfd_cell firmware_devs[] = { { .name ="zynqmp_power_controller" ,@@ -649,7 +651,11 @@ static const struct zynqmp_eemi_ops eemi_ops = {*/ const struct zynqmp_eemi_ops *zynqmp_pm_get_eemi_ops (void ) { -return &eemi_ops; +if (eemi_ops_tbl) +return eemi_ops_tbl; +else +return ERR_PTR (-EPROBE_DEFER ); + }EXPORT_SYMBOL_GPL (zynqmp_pm_get_eemi_ops);@@ -694,6 +700,9 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)pr_info ("%s Trustzone version v%d.%d\n" , __func__, pm_tz_version >>16 , pm_tz_version &0xFFFF ); +/* Assign eemi_ops_table */ + eemi_ops_tbl = &eemi_ops; +zynqmp_pm_api_debugfs_init (); ret = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, firmware_devs,drivers/nvmem/zynqmp_nvmem.c +7
-3@@ -16,6 +16,8 @@ struct zynqmp_nvmem_data {struct nvmem_device *nvmem; }; +static const struct zynqmp_eemi_ops *eemi_ops; +static int zynqmp_nvmem_read (void *context,unsigned int offset,void *val,size_t bytes) {@@ -23,9 +25,7 @@ static int zynqmp_nvmem_read(void *context, unsigned int offset,int idcode, version;struct zynqmp_nvmem_data *priv = context; -const struct zynqmp_eemi_ops *eemi_ops =zynqmp_pm_get_eemi_ops (); - -if (!eemi_ops || !eemi_ops->get_chipid) +if (!eemi_ops->get_chipid)return -ENXIO ; ret = eemi_ops->get_chipid (&idcode, &version);@@ -61,6 +61,10 @@ static int zynqmp_nvmem_probe(struct platform_device *pdev)if (!priv)return -ENOMEM ; + eemi_ops =zynqmp_pm_get_eemi_ops (); +if (IS_ERR (eemi_ops)) +return PTR_ERR (eemi_ops); + priv->dev = dev; econfig.dev = dev; econfig.reg_read = zynqmp_nvmem_read;drivers/reset/reset-zynqmp.c +4
-4@@ -79,11 +79,11 @@ static int zynqmp_reset_probe(struct platform_device *pdev)if (!priv)return -ENOMEM ; -platform_set_drvdata (pdev, priv); - priv->eemi_ops =zynqmp_pm_get_eemi_ops (); -if (!priv->eemi_ops) -return -ENXIO ; +if (IS_ERR (priv->eemi_ops)) +return PTR_ERR (priv->eemi_ops); + +platform_set_drvdata (pdev, priv); priv->rcdev.ops = &zynqmp_reset_ops; priv->rcdev.owner =THIS_MODULE ;drivers/soc/xilinx/zynqmp_pm_domains.c +10
-8@@ -23,6 +23,8 @@/* Flag stating if PM nodes mapped to the PM domain has been requested */ #define ZYNQMP_PM_DOMAIN_REQUESTED BIT(0) +static const struct zynqmp_eemi_ops *eemi_ops; +/** * struct zynqmp_pm_domain - Wrapper around struct generic_pm_domain * @gpd: Generic power domain @@ -71,9 +73,8 @@ static int zynqmp_gpd_power_on(struct generic_pm_domain *domain) {int ret;struct zynqmp_pm_domain *pd; -const struct zynqmp_eemi_ops *eemi_ops =zynqmp_pm_get_eemi_ops (); -if (!eemi_ops || !eemi_ops->set_requirement) +if (!eemi_ops->set_requirement)return -ENXIO ; pd = container_of(domain, struct zynqmp_pm_domain, gpd);@@ -107,9 +108,8 @@ static int zynqmp_gpd_power_off(struct generic_pm_domain *domain)struct zynqmp_pm_domain *pd;u32 capabilities =0 ;bool may_wakeup; -const struct zynqmp_eemi_ops *eemi_ops =zynqmp_pm_get_eemi_ops (); -if (!eemi_ops || !eemi_ops->set_requirement) +if (!eemi_ops->set_requirement)return -ENXIO ; pd = container_of(domain, struct zynqmp_pm_domain, gpd);@@ -160,9 +160,8 @@ static int zynqmp_gpd_attach_dev(struct generic_pm_domain *domain, {int ret;struct zynqmp_pm_domain *pd; -const struct zynqmp_eemi_ops *eemi_ops =zynqmp_pm_get_eemi_ops (); -if (!eemi_ops || !eemi_ops->request_node) +if (!eemi_ops->request_node)return -ENXIO ; pd = container_of(domain, struct zynqmp_pm_domain, gpd);@@ -197,9 +196,8 @@ static void zynqmp_gpd_detach_dev(struct generic_pm_domain *domain, {int ret;struct zynqmp_pm_domain *pd; -const struct zynqmp_eemi_ops *eemi_ops =zynqmp_pm_get_eemi_ops (); -if (!eemi_ops || !eemi_ops->release_node) +if (!eemi_ops->release_node)return ; pd = container_of(domain, struct zynqmp_pm_domain, gpd);@@ -266,6 +264,10 @@ static int zynqmp_gpd_probe(struct platform_device *pdev)struct zynqmp_pm_domain *pd;struct device *dev = &pdev->dev; + eemi_ops =zynqmp_pm_get_eemi_ops (); +if (IS_ERR (eemi_ops)) +return PTR_ERR (eemi_ops); + pd =devm_kcalloc (dev,ZYNQMP_NUM_DOMAINS ,sizeof (*pd),GFP_KERNEL );if (!pd)return -ENOMEM ;drivers/soc/xilinx/zynqmp_power.c +6
-4@@ -31,6 +31,7 @@ static const char *const suspend_modes[] = { };static enum pm_suspend_mode suspend_mode =PM_SUSPEND_MODE_STD ; +static const struct zynqmp_eemi_ops *eemi_ops;enum pm_api_cb_id {PM_INIT_SUSPEND_CB =30 ,@@ -92,9 +93,8 @@ static ssize_t suspend_mode_store(struct device *dev, const char *buf, size_t count) { int md, ret = -EINVAL; -const struct zynqmp_eemi_ops *eemi_ops =zynqmp_pm_get_eemi_ops (); -if (!eemi_ops || !eemi_ops->set_suspend_mode) +if (!eemi_ops->set_suspend_mode)return ret;for (md =PM_SUSPEND_MODE_FIRST ; md <ARRAY_SIZE (suspend_modes); md++)@@ -120,9 +120,11 @@ static int zynqmp_pm_probe(struct platform_device *pdev)int ret, irq;u32 pm_api_version; -const struct zynqmp_eemi_ops *eemi_ops =zynqmp_pm_get_eemi_ops (); + eemi_ops =zynqmp_pm_get_eemi_ops (); +if (IS_ERR (eemi_ops)) +return PTR_ERR (eemi_ops); -if (!eemi_ops || !eemi_ops->get_api_version || !eemi_ops->init_finalize) +if (!eemi_ops->get_api_version || !eemi_ops->init_finalize)return -ENXIO ; eemi_ops->init_finalize ();drivers/spi/spi-zynqmp-gqspi.c +5
-0@@ -138,6 +138,7 @@#define SPI_AUTOSUSPEND_TIMEOUT 3000enum mode_type {GQSPI_MODE_IO ,GQSPI_MODE_DMA }; +static const struct zynqmp_eemi_ops *eemi_ops;/** * struct zynqmp_qspi - Defines qspi driver instance @@ -1021,6 +1022,10 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)struct resource *res;struct device *dev = &pdev->dev; + eemi_ops =zynqmp_pm_get_eemi_ops (); +if (IS_ERR (eemi_ops)) +return PTR_ERR (eemi_ops); + master =spi_alloc_master (&pdev->dev,sizeof (*xqspi));if (!master)return -ENOMEM ;include/linux/firmware/xlnx-zynqmp.h +0
-0
include/linux/firmware/xlnx-zynqmp.h const struct zynqmp_eemi_ops *zynqmp_pm_get_eemi_ops(void); · line 299
Quoted 8 lines
include/linux/firmware/xlnx-zynqmp.h +1
-1@@ -293,7 +293,7 @@ const struct zynqmp_eemi_ops *zynqmp_pm_get_eemi_ops(void);#else static inline struct zynqmp_eemi_ops *zynqmp_pm_get_eemi_ops (void ) { -return NULL ; +return ERR_PTR (-ENODEV ); }#endif
Applied via zynqmp/soc tree.
Thanks,
Michal