Skip to content

Commit

Permalink
fpga: altera-cvp: Preparation for V2 parts.
Browse files Browse the repository at this point in the history
In preparation for adding newer V2 parts that use a FIFO,
reorganize altera_cvp_chk_error() and change the write
function to block based.
V2 parts have a block size matching the FIFO while older
V1 parts write a 32 bit word at a time.

Signed-off-by: Thor Thayer <[email protected]>
Signed-off-by: Moritz Fischer <[email protected]>
  • Loading branch information
tthayer-intel authored and mfischer committed Aug 24, 2019
1 parent eb12511 commit d2083d0
Showing 1 changed file with 43 additions and 26 deletions.
69 changes: 43 additions & 26 deletions drivers/fpga/altera-cvp.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,42 @@ static int altera_cvp_wait_status(struct altera_cvp_conf *conf, u32 status_mask,
return -ETIMEDOUT;
}

static int altera_cvp_chk_error(struct fpga_manager *mgr, size_t bytes)
{
struct altera_cvp_conf *conf = mgr->priv;
u32 val;
int ret;

/* STEP 10 (optional) - check CVP_CONFIG_ERROR flag */
ret = altera_read_config_dword(conf, VSE_CVP_STATUS, &val);
if (ret || (val & VSE_CVP_STATUS_CFG_ERR)) {
dev_err(&mgr->dev, "CVP_CONFIG_ERROR after %zu bytes!\n",
bytes);
return -EPROTO;
}
return 0;
}

static int altera_cvp_send_block(struct altera_cvp_conf *conf,
const u32 *data, size_t len)
{
u32 mask, words = len / sizeof(u32);
int i, remainder;

for (i = 0; i < words; i++)
conf->write_data(conf, *data++);

/* write up to 3 trailing bytes, if any */
remainder = len % sizeof(u32);
if (remainder) {
mask = BIT(remainder * 8) - 1;
if (mask)
conf->write_data(conf, *data & mask);
}

return 0;
}

static int altera_cvp_teardown(struct fpga_manager *mgr,
struct fpga_image_info *info)
{
Expand Down Expand Up @@ -265,39 +301,25 @@ static int altera_cvp_write_init(struct fpga_manager *mgr,
return 0;
}

static inline int altera_cvp_chk_error(struct fpga_manager *mgr, size_t bytes)
{
struct altera_cvp_conf *conf = mgr->priv;
u32 val;

/* STEP 10 (optional) - check CVP_CONFIG_ERROR flag */
altera_read_config_dword(conf, VSE_CVP_STATUS, &val);
if (val & VSE_CVP_STATUS_CFG_ERR) {
dev_err(&mgr->dev, "CVP_CONFIG_ERROR after %zu bytes!\n",
bytes);
return -EPROTO;
}
return 0;
}

static int altera_cvp_write(struct fpga_manager *mgr, const char *buf,
size_t count)
{
struct altera_cvp_conf *conf = mgr->priv;
size_t done, remaining, len;
const u32 *data;
size_t done, remaining;
int status = 0;
u32 mask;

/* STEP 9 - write 32-bit data from RBF file to CVP data register */
data = (u32 *)buf;
remaining = count;
done = 0;

while (remaining >= 4) {
conf->write_data(conf, *data++);
done += 4;
remaining -= 4;
while (remaining) {
len = min(sizeof(u32), remaining);
altera_cvp_send_block(conf, data, len);
data++;
done += len;
remaining -= len;

/*
* STEP 10 (optional) and STEP 11
Expand All @@ -315,11 +337,6 @@ static int altera_cvp_write(struct fpga_manager *mgr, const char *buf,
}
}

/* write up to 3 trailing bytes, if any */
mask = BIT(remaining * 8) - 1;
if (mask)
conf->write_data(conf, *data & mask);

if (altera_cvp_chkcfg)
status = altera_cvp_chk_error(mgr, count);

Expand Down

0 comments on commit d2083d0

Please sign in to comment.