Received: by 2002:ac2:5978:0:0:0:0:0 with SMTP id h24csp1173616lfp; Thu, 16 Sep 2021 07:26:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVl2OJBDd+fGBETq7Obvb6O8TaW4+dVwy+YJjlEs3r8mfno3/ISt6YFxg8iCjYIwyUwEV0 X-Received: by 2002:a1f:2b14:: with SMTP id r20mr3570365vkr.13.1631802384800; Thu, 16 Sep 2021 07:26:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631802384; cv=none; d=google.com; s=arc-20160816; b=PdnmbQ5nVWC1Nx9OBSBw5D9fiixuiw84izcg4TSnncq2rYBsGhLEj/BJO92yVccBTA NiAlhaAz2UTyAeenwmFksouiTISh48r1P0RIMBjN5fNIeEJwn+2vq1QVLnS9XW/JxqRY klurIkrQoTlsoZwVyqgkrWjZPRdi+W+AjY7VfhV4hjnjsn7+QJWxYbWrlH/qedHjF/Cd lYrujlVE8M2Kh32NrKEDhfph+hzHO08AtoLbk4Ke5ASimUInowwojShCp6VJWiBAOEw6 czNWTfnLSWji9M6kmEaLsCfYIWB+Srv1osxDDeFi3qrk1KtQKskwqnev61dB6EMhv8Ak kpPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:in-reply-to:content-disposition :mime-version:references:message-id:subject:to:from:date :dkim-signature; bh=g3fH0kitaRvXNz+rFG1iJUIiYAoVOGco0OLNKw0onqw=; b=LY+xIXrvJQF6bkBFDPHmVB/v1oJb3xBy9fvDR8H8sUeThsm/bWHke90dyMv4gcMGaJ 3K+rHSIAOuMSDd5EDgGnlBzGOgc9+dhZv09kUF8IeAUuX/pyh1eSkLNIDbB5Ojb6gZYl bLi/hDfg2b/xUWTJCJllEfBz3dS2RXG6hIXXTBgl+Fl1oBncQKBHEBdOA64kBk0Qk+BN aEC1BXGddM4a3FkXzU/nNswa0N0uKcTng20R7gikE2JJfBq6i+e1MppP79hRzzYoR0Xv yDTuJvqCRMfhDEe4hkGt/sc+AnuEvdkTGGgEGbOxmi5uuJLe2LV3X6jJ2W90lPXmnvXT Ikyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=NJhri5f7; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c14si1819034uav.63.2021.09.16.07.26.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 16 Sep 2021 07:26:24 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=NJhri5f7; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Received: from localhost ([::1]:32916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mQsLI-0007x3-6Z for alex.bennee@linaro.org; Thu, 16 Sep 2021 10:26:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54504) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQsGp-0000Bx-So; Thu, 16 Sep 2021 10:21:47 -0400 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]:43738) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mQsGo-0005Fo-3R; Thu, 16 Sep 2021 10:21:47 -0400 Received: by mail-oi1-x231.google.com with SMTP id w19so9238303oik.10; Thu, 16 Sep 2021 07:21:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=g3fH0kitaRvXNz+rFG1iJUIiYAoVOGco0OLNKw0onqw=; b=NJhri5f7VkDjs/JtBW9yBxQZjokFbEN2fK1rQJttQBomGW7t50+Wj/Bqds/1vfqZbP FZtgCb3qjW6hRb+YYAHmNlzqg6Y23gKuSsEwecHL/iaTTtI2qDY6zDhSXq0HAzvd/fqf 6pEGrnDVY6ZQkZReBKuLlSeUOao3FcWSBFNF2U17eORJMdWdbU4s1ps1iCh1Qw5RywJG MqrAGP4ZhSH/7X0jP/BMHS+nWBkx6/rKO6kVfPYcl+VEzYN4rDjOGxlnHG9QBJmv3wTF 3Llx0ZiTL2GlObtpql3jMvqcg3Wq5PbvCPg+nUyFaMiXfSJxGlCd47CUQ5OnjEOj23RT r8ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=g3fH0kitaRvXNz+rFG1iJUIiYAoVOGco0OLNKw0onqw=; b=fH+Yqgo9WYr4VIUQp+LovgFzCBNV2fMYBRGthjpuJOWVDrA/odJVtqTgUnEroESB1/ CZMWOdW30hU+ChcZwPKjnhhGVuv3/jHr6ZJoWvsKaf0FArLtsCm9ZafpbnPwjTv3U3vw 3/E5jiA1p027Y0edPF/OYuQmmoAAolFERS3XuLPZYn9ovlZhdoaFBgF275cBTQA0dRBL hsQxufP9TCrtwvbaY67fQrOfoqz0XvYYzU7uYxb81ffqNl8GRJSUmpxABMfEhLtDz/+K MDxv1/CFsLoO24h4sEFwemqQJ1tHuOuC0srzn5X44vzZMBT4tZTUvjKcqeLSo0EyQMag TWBA== X-Gm-Message-State: AOAM5310PJVgKFx7yUHTvbtJieduDT3yydAGcLDsHD//WNEX9cer4vjX U3Z3BTWXmTiai1ggk2tGJx0= X-Received: by 2002:a05:6808:3099:: with SMTP id bl25mr63983oib.44.1631802103800; Thu, 16 Sep 2021 07:21:43 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id f17sm794655otl.24.2021.09.16.07.21.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Sep 2021 07:21:42 -0700 (PDT) Date: Thu, 16 Sep 2021 07:21:40 -0700 From: Guenter Roeck To: "Cheng, Xuzhou" Subject: Re: [PATCH] hw/ssi: imx_spi: Improve chip select handling Message-ID: <20210916142140.GA252836@roeck-us.net> References: <8b86d434-a2e6-8122-0a88-dc9a15fbfe87@roeck-us.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::231; envelope-from=groeck7@gmail.com; helo=mail-oi1-x231.google.com X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Jean-Christophe Dubois , Alistair Francis , Philippe =?iso-8859-1?Q?Mathieu-Daud=E9?= , QEMU Developers , qemu-arm , Bin Meng Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: 8B4x3yFgF5lz 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