提交 9495f264 编写于 作者: K Kedareswara rao Appana 提交者: Vinod Koul

dmaengine: xilinx_vdma: Use readl_poll_timeout instead of do while loop's

It is sometimes necessary to poll a memory-mapped register until its
value satisfies some condition use convenience macros
that do this instead of do while loop's.

This patch updates the same in the driver.
Signed-off-by: NKedareswara rao Appana <appanad@xilinx.com>
Signed-off-by: NVinod Koul <vinod.koul@intel.com>
上级 26c5e369
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/iopoll.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of_address.h> #include <linux/of_address.h>
#include <linux/of_dma.h> #include <linux/of_dma.h>
...@@ -254,6 +255,9 @@ struct xilinx_vdma_device { ...@@ -254,6 +255,9 @@ struct xilinx_vdma_device {
container_of(chan, struct xilinx_vdma_chan, common) container_of(chan, struct xilinx_vdma_chan, common)
#define to_vdma_tx_descriptor(tx) \ #define to_vdma_tx_descriptor(tx) \
container_of(tx, struct xilinx_vdma_tx_descriptor, async_tx) container_of(tx, struct xilinx_vdma_tx_descriptor, async_tx)
#define xilinx_vdma_poll_timeout(chan, reg, val, cond, delay_us, timeout_us) \
readl_poll_timeout(chan->xdev->regs + chan->ctrl_offset + reg, val, \
cond, delay_us, timeout_us)
/* IO accessors */ /* IO accessors */
static inline u32 vdma_read(struct xilinx_vdma_chan *chan, u32 reg) static inline u32 vdma_read(struct xilinx_vdma_chan *chan, u32 reg)
...@@ -550,18 +554,17 @@ static bool xilinx_vdma_is_idle(struct xilinx_vdma_chan *chan) ...@@ -550,18 +554,17 @@ static bool xilinx_vdma_is_idle(struct xilinx_vdma_chan *chan)
*/ */
static void xilinx_vdma_halt(struct xilinx_vdma_chan *chan) static void xilinx_vdma_halt(struct xilinx_vdma_chan *chan)
{ {
int loop = XILINX_VDMA_LOOP_COUNT; int err = 0;
u32 val;
vdma_ctrl_clr(chan, XILINX_VDMA_REG_DMACR, XILINX_VDMA_DMACR_RUNSTOP); vdma_ctrl_clr(chan, XILINX_VDMA_REG_DMACR, XILINX_VDMA_DMACR_RUNSTOP);
/* Wait for the hardware to halt */ /* Wait for the hardware to halt */
do { err = xilinx_vdma_poll_timeout(chan, XILINX_VDMA_REG_DMASR, val,
if (vdma_ctrl_read(chan, XILINX_VDMA_REG_DMASR) & (val & XILINX_VDMA_DMASR_HALTED), 0,
XILINX_VDMA_DMASR_HALTED) XILINX_VDMA_LOOP_COUNT);
break;
} while (loop--);
if (!loop) { if (err) {
dev_err(chan->dev, "Cannot stop channel %p: %x\n", dev_err(chan->dev, "Cannot stop channel %p: %x\n",
chan, vdma_ctrl_read(chan, XILINX_VDMA_REG_DMASR)); chan, vdma_ctrl_read(chan, XILINX_VDMA_REG_DMASR));
chan->err = true; chan->err = true;
...@@ -576,18 +579,17 @@ static void xilinx_vdma_halt(struct xilinx_vdma_chan *chan) ...@@ -576,18 +579,17 @@ static void xilinx_vdma_halt(struct xilinx_vdma_chan *chan)
*/ */
static void xilinx_vdma_start(struct xilinx_vdma_chan *chan) static void xilinx_vdma_start(struct xilinx_vdma_chan *chan)
{ {
int loop = XILINX_VDMA_LOOP_COUNT; int err = 0;
u32 val;
vdma_ctrl_set(chan, XILINX_VDMA_REG_DMACR, XILINX_VDMA_DMACR_RUNSTOP); vdma_ctrl_set(chan, XILINX_VDMA_REG_DMACR, XILINX_VDMA_DMACR_RUNSTOP);
/* Wait for the hardware to start */ /* Wait for the hardware to start */
do { err = xilinx_vdma_poll_timeout(chan, XILINX_VDMA_REG_DMASR, val,
if (!(vdma_ctrl_read(chan, XILINX_VDMA_REG_DMASR) & !(val & XILINX_VDMA_DMASR_HALTED), 0,
XILINX_VDMA_DMASR_HALTED)) XILINX_VDMA_LOOP_COUNT);
break;
} while (loop--);
if (!loop) { if (err) {
dev_err(chan->dev, "Cannot start channel %p: %x\n", dev_err(chan->dev, "Cannot start channel %p: %x\n",
chan, vdma_ctrl_read(chan, XILINX_VDMA_REG_DMASR)); chan, vdma_ctrl_read(chan, XILINX_VDMA_REG_DMASR));
...@@ -754,21 +756,17 @@ static void xilinx_vdma_complete_descriptor(struct xilinx_vdma_chan *chan) ...@@ -754,21 +756,17 @@ static void xilinx_vdma_complete_descriptor(struct xilinx_vdma_chan *chan)
*/ */
static int xilinx_vdma_reset(struct xilinx_vdma_chan *chan) static int xilinx_vdma_reset(struct xilinx_vdma_chan *chan)
{ {
int loop = XILINX_VDMA_LOOP_COUNT; int err = 0;
u32 tmp; u32 tmp;
vdma_ctrl_set(chan, XILINX_VDMA_REG_DMACR, XILINX_VDMA_DMACR_RESET); vdma_ctrl_set(chan, XILINX_VDMA_REG_DMACR, XILINX_VDMA_DMACR_RESET);
tmp = vdma_ctrl_read(chan, XILINX_VDMA_REG_DMACR) &
XILINX_VDMA_DMACR_RESET;
/* Wait for the hardware to finish reset */ /* Wait for the hardware to finish reset */
do { err = xilinx_vdma_poll_timeout(chan, XILINX_VDMA_REG_DMACR, tmp,
tmp = vdma_ctrl_read(chan, XILINX_VDMA_REG_DMACR) & !(tmp & XILINX_VDMA_DMACR_RESET), 0,
XILINX_VDMA_DMACR_RESET; XILINX_VDMA_LOOP_COUNT);
} while (loop-- && tmp);
if (!loop) { if (err) {
dev_err(chan->dev, "reset timeout, cr %x, sr %x\n", dev_err(chan->dev, "reset timeout, cr %x, sr %x\n",
vdma_ctrl_read(chan, XILINX_VDMA_REG_DMACR), vdma_ctrl_read(chan, XILINX_VDMA_REG_DMACR),
vdma_ctrl_read(chan, XILINX_VDMA_REG_DMASR)); vdma_ctrl_read(chan, XILINX_VDMA_REG_DMASR));
...@@ -777,7 +775,7 @@ static int xilinx_vdma_reset(struct xilinx_vdma_chan *chan) ...@@ -777,7 +775,7 @@ static int xilinx_vdma_reset(struct xilinx_vdma_chan *chan)
chan->err = false; chan->err = false;
return 0; return err;
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册