Commit f9adf61e authored by Baolin Wang's avatar Baolin Wang Committed by Mark Brown

spi: sprd: adi: Change hwlock to be optional

Now Spreadtrum ADI controller supplies multiple master accessing channel
to support multiple subsystems accessing, instead of using a hardware
spinlock to synchronize between the multiple subsystems.

To keep backward compatibility, we should change the hardware spinlock
to be optional. Moreover change to use of_hwspin_lock_get_id() function
which return -ENOENT error number to indicate no hwlock support.
Signed-off-by: default avatarBaolin Wang <baolin.wang@linaro.org>
Link: https://lore.kernel.org/r/2abe7dcf210e4197f8c5ece7fc6d6cc1eda8c655.1564125131.git.baolin.wang@linaro.orgSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent e6d722ca
...@@ -165,14 +165,16 @@ static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val) ...@@ -165,14 +165,16 @@ static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val)
int read_timeout = ADI_READ_TIMEOUT; int read_timeout = ADI_READ_TIMEOUT;
unsigned long flags; unsigned long flags;
u32 val, rd_addr; u32 val, rd_addr;
int ret; int ret = 0;
ret = hwspin_lock_timeout_irqsave(sadi->hwlock, if (sadi->hwlock) {
ADI_HWSPINLOCK_TIMEOUT, ret = hwspin_lock_timeout_irqsave(sadi->hwlock,
&flags); ADI_HWSPINLOCK_TIMEOUT,
if (ret) { &flags);
dev_err(sadi->dev, "get the hw lock failed\n"); if (ret) {
return ret; dev_err(sadi->dev, "get the hw lock failed\n");
return ret;
}
} }
/* /*
...@@ -219,7 +221,8 @@ static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val) ...@@ -219,7 +221,8 @@ static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val)
*read_val = val & RD_VALUE_MASK; *read_val = val & RD_VALUE_MASK;
out: out:
hwspin_unlock_irqrestore(sadi->hwlock, &flags); if (sadi->hwlock)
hwspin_unlock_irqrestore(sadi->hwlock, &flags);
return ret; return ret;
} }
...@@ -230,12 +233,14 @@ static int sprd_adi_write(struct sprd_adi *sadi, u32 reg_paddr, u32 val) ...@@ -230,12 +233,14 @@ static int sprd_adi_write(struct sprd_adi *sadi, u32 reg_paddr, u32 val)
unsigned long flags; unsigned long flags;
int ret; int ret;
ret = hwspin_lock_timeout_irqsave(sadi->hwlock, if (sadi->hwlock) {
ADI_HWSPINLOCK_TIMEOUT, ret = hwspin_lock_timeout_irqsave(sadi->hwlock,
&flags); ADI_HWSPINLOCK_TIMEOUT,
if (ret) { &flags);
dev_err(sadi->dev, "get the hw lock failed\n"); if (ret) {
return ret; dev_err(sadi->dev, "get the hw lock failed\n");
return ret;
}
} }
ret = sprd_adi_drain_fifo(sadi); ret = sprd_adi_drain_fifo(sadi);
...@@ -261,7 +266,8 @@ static int sprd_adi_write(struct sprd_adi *sadi, u32 reg_paddr, u32 val) ...@@ -261,7 +266,8 @@ static int sprd_adi_write(struct sprd_adi *sadi, u32 reg_paddr, u32 val)
} }
out: out:
hwspin_unlock_irqrestore(sadi->hwlock, &flags); if (sadi->hwlock)
hwspin_unlock_irqrestore(sadi->hwlock, &flags);
return ret; return ret;
} }
...@@ -476,16 +482,26 @@ static int sprd_adi_probe(struct platform_device *pdev) ...@@ -476,16 +482,26 @@ static int sprd_adi_probe(struct platform_device *pdev)
sadi->slave_pbase = res->start + ADI_SLAVE_OFFSET; sadi->slave_pbase = res->start + ADI_SLAVE_OFFSET;
sadi->ctlr = ctlr; sadi->ctlr = ctlr;
sadi->dev = &pdev->dev; sadi->dev = &pdev->dev;
ret = of_hwspin_lock_get_id_byname(np, "adi"); ret = of_hwspin_lock_get_id(np, 0);
if (ret < 0) { if (ret > 0 || (IS_ENABLED(CONFIG_HWSPINLOCK) && ret == 0)) {
dev_err(&pdev->dev, "can not get the hardware spinlock\n"); sadi->hwlock =
goto put_ctlr; devm_hwspin_lock_request_specific(&pdev->dev, ret);
} if (!sadi->hwlock) {
ret = -ENXIO;
sadi->hwlock = devm_hwspin_lock_request_specific(&pdev->dev, ret); goto put_ctlr;
if (!sadi->hwlock) { }
ret = -ENXIO; } else {
goto put_ctlr; switch (ret) {
case -ENOENT:
dev_info(&pdev->dev, "no hardware spinlock supplied\n");
break;
default:
dev_err(&pdev->dev,
"failed to find hwlock id, %d\n", ret);
/* fall-through */
case -EPROBE_DEFER:
goto put_ctlr;
}
} }
sprd_adi_hw_init(sadi); sprd_adi_hw_init(sadi);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment