[PATCH qemu 20/38] aspeed/smc: handle dummy bytes when doing fast reads
Joel Stanley
joel at jms.id.au
Mon Nov 21 18:25:43 AEDT 2016
On Sat, Nov 19, 2016 at 12:52 AM, Cédric Le Goater <clg at kaod.org> wrote:
> diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c
> index 9596ea94a3bc..c0ae07ef8c96 100644
> --- a/hw/ssi/aspeed_smc.c
> +++ b/hw/ssi/aspeed_smc.c
> @@ -525,27 +534,49 @@ static void aspeed_smc_flash_setup_read(AspeedSMCFlash *fl, uint32_t addr)
> ssi_transfer(s->spi, (addr & 0xff));
> }
>
> +static int aspeed_smc_flash_dummies(const AspeedSMCFlash *fl)
> +{
> + AspeedSMCState *s = fl->controller;
> + uint32_t r_ctrl0 = s->regs[s->r_ctrl0 + fl->id];
> +
> + return ((((r_ctrl0 >> CTRL_DUMMY_HIGH_SHIFT) & 0x1) << 2) |
> + ((r_ctrl0 >> CTRL_DUMMY_LOW_SHIFT) & 0x3)) * 8;
This is crazy :)
It might be easier to read if we had a few local variables. Might not
though, so it's up to you.
> +}
> +
> +static uint64_t aspeed_smc_flash_do_read(AspeedSMCFlash *fl, unsigned size)
> +{
> + AspeedSMCState *s = fl->controller;
> + uint64_t ret = 0;
> + int i;
> +
> + if (fl->cmd == SPI_OP_READ_FAST) {
> + for (i = 0; i < aspeed_smc_flash_dummies(fl); i++) {
> + ssi_transfer(s->spi, 0x0);
Do you need to check the return value here as well, like you do below?
> + }
> + }
> + fl->cmd = 0;
> +
> + for (i = 0; i < size; i++) {
> + ret |= ssi_transfer(s->spi, 0x0) << (8 * i);
> + }
> + return ret;
> +}
More information about the openbmc
mailing list