bus: sunxi-rsb: Support atomic transfers

[ Upstream commit 077686da0e ]

When communicating with a PMIC during system poweroff (pm_power_off()),
IRQs are disabled and we are in a RCU read-side critical section, so we
cannot use wait_for_completion_io_timeout(). Instead, poll the status
register for transfer completion.

Fixes: d787dcdb9c ("bus: sunxi-rsb: Add driver for Allwinner Reduced Serial Bus")
Signed-off-by: Samuel Holland <samuel@sholland.org>
Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Link: https://lore.kernel.org/r/20221114015749.28490-3-samuel@sholland.org
Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Samuel Holland 2022-11-13 19:57:48 -06:00 коммит произвёл Greg Kroah-Hartman
Родитель b1ed61e706
Коммит d1dd119134
1 изменённых файлов: 21 добавлений и 8 удалений

Просмотреть файл

@ -271,6 +271,9 @@ EXPORT_SYMBOL_GPL(sunxi_rsb_driver_register);
/* common code that starts a transfer */ /* common code that starts a transfer */
static int _sunxi_rsb_run_xfer(struct sunxi_rsb *rsb) static int _sunxi_rsb_run_xfer(struct sunxi_rsb *rsb)
{ {
u32 int_mask, status;
bool timeout;
if (readl(rsb->regs + RSB_CTRL) & RSB_CTRL_START_TRANS) { if (readl(rsb->regs + RSB_CTRL) & RSB_CTRL_START_TRANS) {
dev_dbg(rsb->dev, "RSB transfer still in progress\n"); dev_dbg(rsb->dev, "RSB transfer still in progress\n");
return -EBUSY; return -EBUSY;
@ -278,13 +281,23 @@ static int _sunxi_rsb_run_xfer(struct sunxi_rsb *rsb)
reinit_completion(&rsb->complete); reinit_completion(&rsb->complete);
writel(RSB_INTS_LOAD_BSY | RSB_INTS_TRANS_ERR | RSB_INTS_TRANS_OVER, int_mask = RSB_INTS_LOAD_BSY | RSB_INTS_TRANS_ERR | RSB_INTS_TRANS_OVER;
rsb->regs + RSB_INTE); writel(int_mask, rsb->regs + RSB_INTE);
writel(RSB_CTRL_START_TRANS | RSB_CTRL_GLOBAL_INT_ENB, writel(RSB_CTRL_START_TRANS | RSB_CTRL_GLOBAL_INT_ENB,
rsb->regs + RSB_CTRL); rsb->regs + RSB_CTRL);
if (!wait_for_completion_io_timeout(&rsb->complete, if (irqs_disabled()) {
msecs_to_jiffies(100))) { timeout = readl_poll_timeout_atomic(rsb->regs + RSB_INTS,
status, (status & int_mask),
10, 100000);
writel(status, rsb->regs + RSB_INTS);
} else {
timeout = !wait_for_completion_io_timeout(&rsb->complete,
msecs_to_jiffies(100));
status = rsb->status;
}
if (timeout) {
dev_dbg(rsb->dev, "RSB timeout\n"); dev_dbg(rsb->dev, "RSB timeout\n");
/* abort the transfer */ /* abort the transfer */
@ -296,18 +309,18 @@ static int _sunxi_rsb_run_xfer(struct sunxi_rsb *rsb)
return -ETIMEDOUT; return -ETIMEDOUT;
} }
if (rsb->status & RSB_INTS_LOAD_BSY) { if (status & RSB_INTS_LOAD_BSY) {
dev_dbg(rsb->dev, "RSB busy\n"); dev_dbg(rsb->dev, "RSB busy\n");
return -EBUSY; return -EBUSY;
} }
if (rsb->status & RSB_INTS_TRANS_ERR) { if (status & RSB_INTS_TRANS_ERR) {
if (rsb->status & RSB_INTS_TRANS_ERR_ACK) { if (status & RSB_INTS_TRANS_ERR_ACK) {
dev_dbg(rsb->dev, "RSB slave nack\n"); dev_dbg(rsb->dev, "RSB slave nack\n");
return -EINVAL; return -EINVAL;
} }
if (rsb->status & RSB_INTS_TRANS_ERR_DATA) { if (status & RSB_INTS_TRANS_ERR_DATA) {
dev_dbg(rsb->dev, "RSB transfer data error\n"); dev_dbg(rsb->dev, "RSB transfer data error\n");
return -EIO; return -EIO;
} }