Commit a907ade6 authored by Federico Vaga's avatar Federico Vaga

drv: improve the FSM functions to wait for states

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent b09303f3
......@@ -241,6 +241,34 @@ int zfad_set_range(struct fa_dev *fa, struct zio_channel *chan,
return 0;
}
static enum fa100m14b4c_fsm_state fa_fsm_get_state(struct fa_dev *fa)
{
return fa_readl(fa, fa->fa_adc_csr_base, &zfad_regs[ZFA_STA_FSM]);
}
static bool fa_fsm_is_state(struct fa_dev *fa,
enum fa100m14b4c_fsm_state state)
{
return fa_fsm_get_state(fa) == state;
}
int fa_fsm_wait_state(struct fa_dev *fa,
enum fa100m14b4c_fsm_state state,
unsigned int timeout_us)
{
unsigned long timeout;
timeout = jiffies + usecs_to_jiffies(timeout_us);
while (!fa_fsm_is_state(fa, state)) {
cpu_relax();
if (time_after(jiffies, timeout))
return -ETIMEDOUT;
}
return 0;
}
/*
* zfad_fsm_command
* @fa: the fmc-adc descriptor
......
......@@ -86,30 +86,6 @@ static uint32_t zfad_dev_mem_offset(struct zio_cset *cset)
return dev_mem_off;
}
/**
* zfad_wait_idle
* @cset: ZIO channel set
* @try: how many times poll for IDLE
* @udelay: us between two consecutive delay
*
* @return: it returns 0 on success. If the IDLE status never comes, then it returns
* the status value
*/
static int zfad_wait_idle(struct zio_cset *cset, unsigned int try,
unsigned int udelay)
{
struct fa_dev *fa = cset->zdev->priv_d;
uint32_t val = 0;
while (try-- && val != FA100M14B4C_STATE_IDLE) {
udelay(udelay);
val = fa_readl(fa, fa->fa_adc_csr_base,
&zfad_regs[ZFA_STA_FSM]);
}
return val != FA100M14B4C_STATE_IDLE ? val : 0;
}
static unsigned int zfad_block_n_pages(struct zio_block *block)
{
unsigned int nr_pages;
......@@ -416,7 +392,7 @@ static int zfad_dma_start(struct zio_cset *cset)
}
dma_dev_id = r->start;
err = zfad_wait_idle(cset, 5, 1);
err = fa_fsm_wait_state(fa, FA100M14B4C_STATE_IDLE, 10);
if (err) {
dev_warn(fa->msgdev,
"Can't start DMA on the last acquisition, "
......
......@@ -607,6 +607,9 @@ extern void zfad_reset_offset(struct fa_dev *fa);
extern int zfad_convert_hw_range(uint32_t bitmask);
extern int32_t fa_temperature_read(struct fa_dev *fa);
extern int fa_trigger_software(struct fa_dev *fa);
extern int fa_fsm_wait_state(struct fa_dev *fa,
enum fa100m14b4c_fsm_state state,
unsigned int timeout_us);
/* Temporarily, user values are the same as hardware values */
extern int zfad_convert_user_range(uint32_t user_val);
......
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