From: Guenter Roeck <linux@roeck-us.net>
To: "Cheng, Xuzhou" <Xuzhou.Cheng@windriver.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Jean-Christophe Dubois" <jcd@tribudubois.net>,
"Alistair Francis" <alistair@alistair23.me>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
"QEMU Developers" <qemu-devel@nongnu.org>,
qemu-arm <qemu-arm@nongnu.org>, "Bin Meng" <bmeng.cn@gmail.com>
Subject: Re: [PATCH] hw/ssi: imx_spi: Improve chip select handling
Date: Thu, 16 Sep 2021 07:21:40 -0700 [thread overview]
Message-ID: <20210916142140.GA252836@roeck-us.net> (raw)
In-Reply-To: <PH0PR11MB5205684F9CDEC890187D09D997DC9@PH0PR11MB5205.namprd11.prod.outlook.com>
On Thu, Sep 16, 2021 at 10:21:16AM +0000, Cheng, Xuzhou wrote:
> > diff --git a/hw/ssi/imx_spi.c b/hw/ssi/imx_spi.c
> > index 189423bb3a..7a093156bd 100644
> > --- a/hw/ssi/imx_spi.c
> > +++ b/hw/ssi/imx_spi.c
> > @@ -167,6 +167,8 @@ static void imx_spi_flush_txfifo(IMXSPIState *s)
> > DPRINTF("Begin: TX Fifo Size = %d, RX Fifo Size = %d\n",
> > fifo32_num_used(&s->tx_fifo), fifo32_num_used(&s->rx_fifo));
> >
> > + qemu_set_irq(s->cs_lines[imx_spi_selected_channel(s)], 0);
> > +
> > while (!fifo32_is_empty(&s->tx_fifo)) {
> > int tx_burst = 0;
> >
> > @@ -385,13 +387,6 @@ static void imx_spi_write(void *opaque, hwaddr offset, uint64_t value,
> > case ECSPI_CONREG:
> > s->regs[ECSPI_CONREG] = value;
> >
> > - burst = EXTRACT(s->regs[ECSPI_CONREG], ECSPI_CONREG_BURST_LENGTH) + 1;
> > - if (burst % 8) {
> > - qemu_log_mask(LOG_UNIMP,
> > - "[%s]%s: burst length %d not supported: rounding up to next multiple of 8\n",
> > - TYPE_IMX_SPI, __func__, burst);
> > - }
> > -
> > if (!imx_spi_is_enabled(s)) {
> > /* device is disabled, so this is a soft reset */
> > imx_spi_soft_reset(s);
> > @@ -404,9 +399,11 @@ static void imx_spi_write(void *opaque, hwaddr offset, uint64_t value,
> >
> > /* We are in master mode */
> >
> > - for (i = 0; i < ECSPI_NUM_CS; i++) {
> > - qemu_set_irq(s->cs_lines[i],
> > - i == imx_spi_selected_channel(s) ? 0 : 1);
> > + burst = EXTRACT(s->regs[ECSPI_CONREG], ECSPI_CONREG_BURST_LENGTH);
> > + if (burst == 0) {
> > + for (i = 0; i < ECSPI_NUM_CS; i++) {
> > + qemu_set_irq(s->cs_lines[i], 1);
> > + }
> > }
>
> I got some free time in the past days to investigate this issue. Guenter is right, the Linux imx-spi driver does not work on QEMU.
>
> The reason is that the state of m25p80 machine loops in STATE_READING_DATA state after receiving RDSR command, the new command is ignored. Before sending a new command, the CS line should be pulled to high, this make the state of m25p80 back to IDLE.
>
> I have same point with Guenter, it's that set CS to 1 when burst is zero. But i don't think it is necessary to set CS to 0 in imx_spi_flush_txfifo(). I will send a new patch to fix this issue.
>
Thanks a lot for looking into this. If you have a better solution than mine, by
all means, please go for it. As I mentioned in my patch, I didn't really like
it, but I was unable to find a better solution.
> BTW, the Linux driver uses DMA mode when transfer length is greater than the FIFO size, But QEMU imx-spi model doesn't support DMA now.
Does it have practical impact ? Obviously my tests were somewhat limited (I was
happy to get Linux booting from flash), but I don't recall seeing a problem.
Thanks,
Guenter
next prev parent reply other threads:[~2021-09-16 14:27 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-08 1:34 [PATCH] hw/ssi: imx_spi: Improve chip select handling Guenter Roeck
2021-09-02 15:58 ` Peter Maydell
2021-09-02 16:09 ` Guenter Roeck
2021-09-02 19:29 ` Peter Maydell
2021-09-04 17:13 ` Guenter Roeck
2021-09-04 23:06 ` Bin Meng
2021-09-04 23:19 ` Philippe Mathieu-Daudé
2021-09-05 2:08 ` Guenter Roeck
2021-09-08 6:29 ` Bin Meng
2021-09-08 6:31 ` Bin Meng
2021-09-08 9:05 ` Cheng, Xuzhou
2021-09-08 16:52 ` Guenter Roeck
2021-09-16 10:21 ` Cheng, Xuzhou
2021-09-16 14:21 ` Guenter Roeck [this message]
2021-09-18 3:09 ` Cheng, Xuzhou
2021-09-18 4:19 ` Guenter Roeck
2021-09-26 2:49 ` Bin Meng
2021-10-01 13:04 ` Guenter Roeck
2021-09-05 2:05 ` Guenter Roeck
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=20210916142140.GA252836@roeck-us.net \
--to=linux@roeck-us.net \
--cc=Xuzhou.Cheng@windriver.com \
--cc=alistair@alistair23.me \
--cc=bmeng.cn@gmail.com \
--cc=f4bug@amsat.org \
--cc=jcd@tribudubois.net \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).