Skip to content

Commit 3d03137

Browse files
rajanv-xilinxMichal Simek
authored andcommitted
drivers: Defer probe if firmware is not ready
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 <rajan.vaja@xilinx.com> Signed-off-by: Jolly Shah <jollys@xilinx.com> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
1 parent b9472f7 commit 3d03137

10 files changed

Lines changed: 47 additions & 28 deletions

File tree

‎Documentation/xilinx/eemi.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ Example of EEMI ops usage:
4141
int ret;
4242

4343
eemi_ops = zynqmp_pm_get_eemi_ops();
44-
if (!eemi_ops)
45-
return -ENXIO;
44+
if (IS_ERR(eemi_ops))
45+
return PTR_ERR(eemi_ops);
4646

4747
ret = eemi_ops->query_data(qdata, ret_payload);
4848

‎drivers/clk/zynqmp/clkc.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,8 @@ static int zynqmp_clock_probe(struct platform_device *pdev)
695695
struct device *dev = &pdev->dev;
696696

697697
eemi_ops = zynqmp_pm_get_eemi_ops();
698-
if (!eemi_ops)
699-
return -ENXIO;
698+
if (IS_ERR(eemi_ops))
699+
return PTR_ERR(eemi_ops);
700700

701701
ret = zynqmp_clk_setup(dev->of_node);
702702

‎drivers/firmware/xilinx/zynqmp-debug.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ static int process_api_request(u32 pm_id, u64 *pm_api_arg, u32 *pm_api_ret)
9090
int ret;
9191
struct zynqmp_pm_query_data qdata = {0};
9292

93-
if (!eemi_ops)
94-
return -ENXIO;
95-
9693
switch (pm_id) {
9794
case PM_GET_API_VERSION:
9895
ret = eemi_ops->get_api_version(&pm_api_version);

‎drivers/firmware/xilinx/zynqmp.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <linux/firmware/xlnx-zynqmp.h>
2525
#include "zynqmp-debug.h"
2626

27+
static const struct zynqmp_eemi_ops *eemi_ops_tbl;
28+
2729
static const struct mfd_cell firmware_devs[] = {
2830
{
2931
.name = "zynqmp_power_controller",
@@ -649,7 +651,11 @@ static const struct zynqmp_eemi_ops eemi_ops = {
649651
*/
650652
const struct zynqmp_eemi_ops *zynqmp_pm_get_eemi_ops(void)
651653
{
652-
return &eemi_ops;
654+
if (eemi_ops_tbl)
655+
return eemi_ops_tbl;
656+
else
657+
return ERR_PTR(-EPROBE_DEFER);
658+
653659
}
654660
EXPORT_SYMBOL_GPL(zynqmp_pm_get_eemi_ops);
655661

@@ -694,6 +700,9 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)
694700
pr_info("%s Trustzone version v%d.%d\n", __func__,
695701
pm_tz_version >> 16, pm_tz_version & 0xFFFF);
696702

703+
/* Assign eemi_ops_table */
704+
eemi_ops_tbl = &eemi_ops;
705+
697706
zynqmp_pm_api_debugfs_init();
698707

699708
ret = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, firmware_devs,

‎drivers/nvmem/zynqmp_nvmem.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ struct zynqmp_nvmem_data {
1616
struct nvmem_device *nvmem;
1717
};
1818

19+
static const struct zynqmp_eemi_ops *eemi_ops;
20+
1921
static int zynqmp_nvmem_read(void *context, unsigned int offset,
2022
void *val, size_t bytes)
2123
{
2224
int ret;
2325
int idcode, version;
2426
struct zynqmp_nvmem_data *priv = context;
2527

26-
const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
27-
28-
if (!eemi_ops || !eemi_ops->get_chipid)
28+
if (!eemi_ops->get_chipid)
2929
return -ENXIO;
3030

3131
ret = eemi_ops->get_chipid(&idcode, &version);
@@ -61,6 +61,10 @@ static int zynqmp_nvmem_probe(struct platform_device *pdev)
6161
if (!priv)
6262
return -ENOMEM;
6363

64+
eemi_ops = zynqmp_pm_get_eemi_ops();
65+
if (IS_ERR(eemi_ops))
66+
return PTR_ERR(eemi_ops);
67+
6468
priv->dev = dev;
6569
econfig.dev = dev;
6670
econfig.reg_read = zynqmp_nvmem_read;

‎drivers/reset/reset-zynqmp.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ static int zynqmp_reset_probe(struct platform_device *pdev)
7979
if (!priv)
8080
return -ENOMEM;
8181

82-
platform_set_drvdata(pdev, priv);
83-
8482
priv->eemi_ops = zynqmp_pm_get_eemi_ops();
85-
if (!priv->eemi_ops)
86-
return -ENXIO;
83+
if (IS_ERR(priv->eemi_ops))
84+
return PTR_ERR(priv->eemi_ops);
85+
86+
platform_set_drvdata(pdev, priv);
8787

8888
priv->rcdev.ops = &zynqmp_reset_ops;
8989
priv->rcdev.owner = THIS_MODULE;

‎drivers/soc/xilinx/zynqmp_pm_domains.c‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
/* Flag stating if PM nodes mapped to the PM domain has been requested */
2424
#define ZYNQMP_PM_DOMAIN_REQUESTED BIT(0)
2525

26+
static const struct zynqmp_eemi_ops *eemi_ops;
27+
2628
/**
2729
* struct zynqmp_pm_domain - Wrapper around struct generic_pm_domain
2830
* @gpd: Generic power domain
@@ -71,9 +73,8 @@ static int zynqmp_gpd_power_on(struct generic_pm_domain *domain)
7173
{
7274
int ret;
7375
struct zynqmp_pm_domain *pd;
74-
const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
7576

76-
if (!eemi_ops || !eemi_ops->set_requirement)
77+
if (!eemi_ops->set_requirement)
7778
return -ENXIO;
7879

7980
pd = container_of(domain, struct zynqmp_pm_domain, gpd);
@@ -107,9 +108,8 @@ static int zynqmp_gpd_power_off(struct generic_pm_domain *domain)
107108
struct zynqmp_pm_domain *pd;
108109
u32 capabilities = 0;
109110
bool may_wakeup;
110-
const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
111111

112-
if (!eemi_ops || !eemi_ops->set_requirement)
112+
if (!eemi_ops->set_requirement)
113113
return -ENXIO;
114114

115115
pd = container_of(domain, struct zynqmp_pm_domain, gpd);
@@ -160,9 +160,8 @@ static int zynqmp_gpd_attach_dev(struct generic_pm_domain *domain,
160160
{
161161
int ret;
162162
struct zynqmp_pm_domain *pd;
163-
const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
164163

165-
if (!eemi_ops || !eemi_ops->request_node)
164+
if (!eemi_ops->request_node)
166165
return -ENXIO;
167166

168167
pd = container_of(domain, struct zynqmp_pm_domain, gpd);
@@ -197,9 +196,8 @@ static void zynqmp_gpd_detach_dev(struct generic_pm_domain *domain,
197196
{
198197
int ret;
199198
struct zynqmp_pm_domain *pd;
200-
const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
201199

202-
if (!eemi_ops || !eemi_ops->release_node)
200+
if (!eemi_ops->release_node)
203201
return;
204202

205203
pd = container_of(domain, struct zynqmp_pm_domain, gpd);
@@ -266,6 +264,10 @@ static int zynqmp_gpd_probe(struct platform_device *pdev)
266264
struct zynqmp_pm_domain *pd;
267265
struct device *dev = &pdev->dev;
268266

267+
eemi_ops = zynqmp_pm_get_eemi_ops();
268+
if (IS_ERR(eemi_ops))
269+
return PTR_ERR(eemi_ops);
270+
269271
pd = devm_kcalloc(dev, ZYNQMP_NUM_DOMAINS, sizeof(*pd), GFP_KERNEL);
270272
if (!pd)
271273
return -ENOMEM;

‎drivers/soc/xilinx/zynqmp_power.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static const char *const suspend_modes[] = {
3131
};
3232

3333
static enum pm_suspend_mode suspend_mode = PM_SUSPEND_MODE_STD;
34+
static const struct zynqmp_eemi_ops *eemi_ops;
3435

3536
enum pm_api_cb_id {
3637
PM_INIT_SUSPEND_CB = 30,
@@ -92,9 +93,8 @@ static ssize_t suspend_mode_store(struct device *dev,
9293
const char *buf, size_t count)
9394
{
9495
int md, ret = -EINVAL;
95-
const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
9696

97-
if (!eemi_ops || !eemi_ops->set_suspend_mode)
97+
if (!eemi_ops->set_suspend_mode)
9898
return ret;
9999

100100
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)
120120
int ret, irq;
121121
u32 pm_api_version;
122122

123-
const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
123+
eemi_ops = zynqmp_pm_get_eemi_ops();
124+
if (IS_ERR(eemi_ops))
125+
return PTR_ERR(eemi_ops);
124126

125-
if (!eemi_ops || !eemi_ops->get_api_version || !eemi_ops->init_finalize)
127+
if (!eemi_ops->get_api_version || !eemi_ops->init_finalize)
126128
return -ENXIO;
127129

128130
eemi_ops->init_finalize();

‎drivers/spi/spi-zynqmp-gqspi.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138

139139
#define SPI_AUTOSUSPEND_TIMEOUT 3000
140140
enum mode_type {GQSPI_MODE_IO, GQSPI_MODE_DMA};
141+
static const struct zynqmp_eemi_ops *eemi_ops;
141142

142143
/**
143144
* struct zynqmp_qspi - Defines qspi driver instance
@@ -1021,6 +1022,10 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
10211022
struct resource *res;
10221023
struct device *dev = &pdev->dev;
10231024

1025+
eemi_ops = zynqmp_pm_get_eemi_ops();
1026+
if (IS_ERR(eemi_ops))
1027+
return PTR_ERR(eemi_ops);
1028+
10241029
master = spi_alloc_master(&pdev->dev, sizeof(*xqspi));
10251030
if (!master)
10261031
return -ENOMEM;

‎include/linux/firmware/xlnx-zynqmp.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ const struct zynqmp_eemi_ops *zynqmp_pm_get_eemi_ops(void);
293293
#else
294294
static inline struct zynqmp_eemi_ops *zynqmp_pm_get_eemi_ops(void)
295295
{
296-
return NULL;
296+
return ERR_PTR(-ENODEV);
297297
}
298298
#endif
299299

0 commit comments

Comments
 (0)