All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@kaod.org>
To: "mar.krzeminski" <mar.krzeminski@gmail.com>,
	Peter Maydell <peter.maydell@linaro.org>
Cc: Peter Crosthwaite <crosthwaite.peter@gmail.com>,
	Andrew Jeffery <andrew@aj.id.au>,
	Marcin Krzeminski <marcin.krzeminski@nokia.com>,
	qemu-devel@nongnu.org, qemu-arm@nongnu.org
Subject: Re: [Qemu-devel] [PATCH for-2.9 22/30] aspeed/smc: handle dummy bytes when doing fast reads
Date: Mon, 5 Dec 2016 15:14:58 +0100	[thread overview]
Message-ID: <09b0e4b9-faae-34aa-4042-aa3704c3457b@kaod.org> (raw)
In-Reply-To: <f3a5657c-39db-75a9-3bfc-25e5d03b7e1e@gmail.com>

On 12/04/2016 05:46 PM, mar.krzeminski wrote:
> 
> 
> W dniu 29.11.2016 o 16:44, Cédric Le Goater pisze:
>> When doing fast read, a certain amount of dummy bytes should be sent
>> before the read. This number is configurable in the controler CE0
>> Control Register and needs to be modeled using fake transfers the
>> flash module.
>>
>> When the controller is configured for Command mode, the SPI command
>> used to do the read is stored in the CE0 control register but, in User
>> mode, we need to snoop into the flow of bytes to catch the command. It
>> should be the first byte after CS select.
>>
>> Signed-off-by: Cédric Le Goater <clg@kaod.org>
>> Reviewed-by: Andrew Jeffery <andrew@aj.id.au>
>> ---
>>  hw/ssi/aspeed_smc.c         | 58 ++++++++++++++++++++++++++++++++++++++-------
>>  include/hw/ssi/aspeed_smc.h |  1 +
>>  2 files changed, 51 insertions(+), 8 deletions(-)
>>
>> diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c
>> index 9596ea94a3bc..733fd8b09c06 100644
>> --- a/hw/ssi/aspeed_smc.c
>> +++ b/hw/ssi/aspeed_smc.c
>> @@ -71,7 +71,9 @@
>>  #define R_CTRL0           (0x10 / 4)
>>  #define   CTRL_CMD_SHIFT           16
>>  #define   CTRL_CMD_MASK            0xff
>> +#define   CTRL_DUMMY_HIGH_SHIFT    14
>>  #define   CTRL_AST2400_SPI_4BYTE   (1 << 13)
>> +#define   CTRL_DUMMY_LOW_SHIFT     6 /* 2 bits [7:6] */
>>  #define   CTRL_CE_STOP_ACTIVE      (1 << 2)
>>  #define   CTRL_CMD_MODE_MASK       0x3
>>  #define     CTRL_READMODE          0x0
>> @@ -151,6 +153,7 @@
>>  #define SPI_OP_WRDI       0x04    /* Write disable */
>>  #define SPI_OP_RDSR       0x05    /* Read status register */
>>  #define SPI_OP_WREN       0x06    /* Write enable */
>> +#define SPI_OP_READ_FAST  0x0b    /* Read data bytes (high frequency) */
>>  
>>  /* Used for Macronix and Winbond flashes. */
>>  #define SPI_OP_EN4B       0xb7    /* Enter 4-byte mode */
>> @@ -510,6 +513,12 @@ static void aspeed_smc_flash_setup_read(AspeedSMCFlash *fl, uint32_t addr)
>>      /* access can not exceed CS segment */
>>      addr = aspeed_smc_check_segment_addr(fl, addr);
>>  
>> +    /*
>> +     * Remember command as we might need to send dummy bytes before
>> +     * reading data
>> +     */
>> +    fl->cmd = cmd;
>> +
>>      /* TODO: do we have to send 4BYTE each time ? */
>>      if (aspeed_smc_flash_is_4byte(fl)) {
>>          ssi_transfer(s->spi, SPI_OP_EN4B);
>> @@ -525,27 +534,50 @@ 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];
>> +    uint32_t dummy_high = (r_ctrl0 >> CTRL_DUMMY_HIGH_SHIFT) & 0x1;
>> +    uint32_t dummy_low = (r_ctrl0 >> CTRL_DUMMY_LOW_SHIFT) & 0x3;
>> +
>> +    return ((dummy_high << 2) | dummy_low) * 8;
>> +}
>> +
>> +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);
>> +        }
>> +    }
> Generally this is wrong, controller should be not aware of any command in user mode.
> Currently you are forced to do this by m25p80c dummy cycles implementation.
> I had no time to improve this since it need to update in Xilinx models, but maybe it is good place to talk about the solution.
> I was thinking to add to ssi function transferN, and use it in flash models.
> Firs introduce new state for dummy cycles in m25p80 and then:

This new state would depend on the command op ? fastread would put
the object in a dummy_cycle state ? 

> a) in case caller use ssi_transfer(transfer8 in flsh models) dummy count will be incremented by 8.
> This should solve the problem when flash is connected to controller that is not aware about dummy cycles,
> like this mode or clear SPI controller.
> b) when caller use ssi_trasferN length (in bits) will be the number of dummy cycles.
> 
> What is your opinion?

when you have some time, please send a quick rfc patch for the API :) 
so that I can experiment on the aspeed controller.

Thanks,

C. 

>> +    fl->cmd = 0;
>> +
>> +    for (i = 0; i < size; i++) {
>> +        ret |= ssi_transfer(s->spi, 0x0) << (8 * i);
>> +    }
>> +    return ret;
>> +}
>> +
>>  static uint64_t aspeed_smc_flash_read(void *opaque, hwaddr addr, unsigned size)
>>  {
>>      AspeedSMCFlash *fl = opaque;
>> -    const AspeedSMCState *s = fl->controller;
>>      uint64_t ret = 0;
>> -    int i;
>>  
>>      switch (aspeed_smc_flash_mode(fl)) {
>>      case CTRL_USERMODE:
>> -        for (i = 0; i < size; i++) {
>> -            ret |= ssi_transfer(s->spi, 0x0) << (8 * i);
>> -        }
>> +        ret = aspeed_smc_flash_do_read(fl, size);
>>          break;
>>      case CTRL_READMODE:
>>      case CTRL_FREADMODE:
>>          aspeed_smc_flash_select(fl);
>>          aspeed_smc_flash_setup_read(fl, addr);
>>  
>> -        for (i = 0; i < size; i++) {
>> -            ret |= ssi_transfer(s->spi, 0x0) << (8 * i);
>> -        }
>> +        ret = aspeed_smc_flash_do_read(fl, size);
>>  
>>          aspeed_smc_flash_unselect(fl);
>>          break;
>> @@ -596,6 +628,15 @@ static void aspeed_smc_flash_write(void *opaque, hwaddr addr, uint64_t data,
>>  
>>      switch (aspeed_smc_flash_mode(fl)) {
>>      case CTRL_USERMODE:
>> +        /*
>> +         * First write after chip select is the chip command. Remember
>> +         * it as we might need to send dummy bytes before reading
>> +         * data. It will be reseted when the chip is unselected.
>> +         */
>> +        if (!fl->cmd) {
>> +            fl->cmd = data & 0xff;
>> +        }
>> +
>>          for (i = 0; i < size; i++) {
>>              ssi_transfer(s->spi, (data >> (8 * i)) & 0xff);
>>          }
>> @@ -629,6 +670,7 @@ static const MemoryRegionOps aspeed_smc_flash_ops = {
>>  static void aspeed_smc_flash_update_cs(AspeedSMCFlash *fl)
>>  {
>>      AspeedSMCState *s = fl->controller;
>> +    fl->cmd = 0;
>>      qemu_set_irq(s->cs_lines[fl->id], aspeed_smc_is_ce_stop_active(fl));
>>  }
>>  
>> diff --git a/include/hw/ssi/aspeed_smc.h b/include/hw/ssi/aspeed_smc.h
>> index 88a904849801..3ae0a369073d 100644
>> --- a/include/hw/ssi/aspeed_smc.h
>> +++ b/include/hw/ssi/aspeed_smc.h
>> @@ -52,6 +52,7 @@ typedef struct AspeedSMCFlash {
>>  
>>      uint8_t id;
>>      uint32_t size;
>> +    uint8_t cmd;
>>  
>>      MemoryRegion mmio;
>>      DeviceState *flash;
> 

  reply	other threads:[~2016-12-05 14:15 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-29 15:43 [Qemu-devel] [PATCH for-2.9 00/30] Aspeed SoC fixes and model improvements Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 01/30] target-arm: Add VBAR support to ARM1176 CPUs Cédric Le Goater
2016-12-14 15:43   ` Peter Maydell
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 02/30] m25p80: add support for the mx66l1g45g Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 03/30] aspeed: QOMify the CPU object and attach it to the SoC Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 04/30] aspeed: remove cannot_destroy_with_object_finalize_yet Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 05/30] aspeed: attach the second SPI controller object to the SoC Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 06/30] aspeed: extend the board configuration with flash models Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 07/30] aspeed: add support for the romulus-bmc board Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 08/30] aspeed: add a memory region for SRAM Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 09/30] aspeed: add the definitions for the AST2400 A1 SoC Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 10/30] aspeed: change SoC revision of the palmetto-bmc machine Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 11/30] aspeed/scu: fix SCU region size Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 12/30] aspeed/smc: improve segment register support Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 13/30] aspeed/smc: set the number of flash modules for the FMC controller Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 14/30] aspeed/smc: rework the prototype of the AspeedSMCFlash helper routines Cédric Le Goater
2016-12-14 17:09   ` Peter Maydell
2016-12-15 13:38     ` Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 15/30] aspeed/smc: introduce a aspeed_smc_flash_update_cs() helper Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 16/30] aspeed/smc: autostrap CE0/1 configuration Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 17/30] aspeed/smc: handle SPI flash Command mode Cédric Le Goater
2016-12-04 16:31   ` mar.krzeminski
2016-12-05 14:07     ` Cédric Le Goater
2016-12-05 15:33       ` mar.krzeminski
2017-01-02 15:56         ` Cédric Le Goater
2017-01-02 17:33           ` mar.krzeminski
2017-01-02 18:02             ` Cédric Le Goater
2017-01-02 18:21               ` mar.krzeminski
2017-01-03 10:50                 ` Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 18/30] aspeed/smc: extend tests for " Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 19/30] aspeed/smc: unfold the AspeedSMCController array Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 20/30] aspeed/smc: add a 'sdram_base' property Cédric Le Goater
2016-11-29 15:43 ` [Qemu-devel] [PATCH for-2.9 21/30] aspeed/smc: add support for DMAs Cédric Le Goater
2016-11-29 15:44 ` [Qemu-devel] [PATCH for-2.9 22/30] aspeed/smc: handle dummy bytes when doing fast reads Cédric Le Goater
2016-12-04 16:46   ` mar.krzeminski
2016-12-05 14:14     ` Cédric Le Goater [this message]
2016-12-05 15:12       ` mar.krzeminski
2016-11-29 15:44 ` [Qemu-devel] [PATCH for-2.9 23/30] aspeed/smc: adjust the size of the register region Cédric Le Goater
2016-11-29 15:44 ` [Qemu-devel] [PATCH for-2.9 24/30] aspeed: use first SPI flash as a boot ROM Cédric Le Goater
2016-12-04 17:00   ` mar.krzeminski
2016-12-05  9:36     ` Cédric Le Goater
2016-12-05  9:57       ` Marcin Krzemiński
2016-12-05 14:53         ` Cédric Le Goater
2016-12-05 15:09           ` mar.krzeminski
2016-11-29 15:44 ` [Qemu-devel] [PATCH for-2.9 25/30] block: add a model option for MTD devices Cédric Le Goater
2016-11-29 16:06   ` Cédric Le Goater
2016-11-29 17:30   ` Cédric Le Goater
2016-11-29 18:08     ` Kevin Wolf
2016-11-30 15:09       ` Cédric Le Goater
2016-11-30 15:55         ` Kevin Wolf
2016-11-29 15:44 ` [Qemu-devel] [PATCH for-2.9 26/30] aspeed/smc: use flash model option Cédric Le Goater
2016-11-30 16:26   ` Cédric Le Goater
2016-11-29 15:44 ` [Qemu-devel] [PATCH for-2.9 27/30] wdt: Add Aspeed watchdog device model Cédric Le Goater
2017-01-16 17:14   ` Cédric Le Goater
2016-11-29 15:44 ` [Qemu-devel] [PATCH for-2.9 28/30] aspeed: add a watchdog controller Cédric Le Goater
2016-11-30  2:01   ` Andrew Jeffery
2016-11-29 16:07 ` [Qemu-devel] [PATCH for-2.9 29/30] aspeed/scu: add a aspeed_scu_get_clk() helper Cédric Le Goater
2016-11-29 16:07   ` [Qemu-devel] [PATCH for-2.9 30/30] wdt: aspeed: use scu to get clock freq Cédric Le Goater
2016-11-29 19:17     ` Cédric Le Goater
2016-11-29 19:16   ` [Qemu-devel] [PATCH for-2.9 29/30] aspeed/scu: add a aspeed_scu_get_clk() helper Cédric Le Goater
2016-11-29 17:26 ` Cédric Le Goater
2016-11-29 17:26   ` [Qemu-devel] [PATCH for-2.9 30/30] wdt: aspeed: use scu to get clock freq Cédric Le Goater
2016-12-14 17:12 ` [Qemu-devel] [PATCH for-2.9 00/30] Aspeed SoC fixes and model improvements Peter Maydell
2016-12-14 17:51   ` Cédric Le Goater

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=09b0e4b9-faae-34aa-4042-aa3704c3457b@kaod.org \
    --to=clg@kaod.org \
    --cc=andrew@aj.id.au \
    --cc=crosthwaite.peter@gmail.com \
    --cc=mar.krzeminski@gmail.com \
    --cc=marcin.krzeminski@nokia.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.