From nobody Tue Feb 10 02:00:45 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.208.54 as permitted sender) client-ip=209.85.208.54; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ed1-f54.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.208.54 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1610476607; cv=none; d=zohomail.com; s=zohoarc; b=YWcCbKykfMQij4A/cJBm/OJLIdhgO+M6SkaBr8h3gcSQI+YG29gZ9oGfBiND1xnyRBziOVn6kHxM7/Z3cffidmXFN1r9+tFZbjI5x/PkR7wLCPUVMfd+4GGghUiRws+RZyL4cW8UKG/I5eLAKEVIbe5nw9tpJgn/x2rH2SWF1GY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610476607; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4l0kq3wxIJBsGcT12cxU3gmDmz9IWzR6E0aRKmJTUjQ=; b=TD9uVcrsRskCSO/n7E7jnpCJjzaGCPLvQcwaAv/nt0PPLwb+cPMNScL5Uh39zsf/2Iya9dwm1eb3j/dJxG22UqruUFcOgLLH4b0t08ElfxDDPA2T7OgMKF3MEdhEsBUEkkQmOxxxxk5srx9xtTE/16oon+0cCq6yoIZ4FZM7Bao= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.208.54 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) by mx.zohomail.com with SMTPS id 1610476607702815.3293446007675; Tue, 12 Jan 2021 10:36:47 -0800 (PST) Received: by mail-ed1-f54.google.com with SMTP id i24so3448969edj.8 for ; Tue, 12 Jan 2021 10:36:46 -0800 (PST) Return-Path: Return-Path: Received: from x1w.redhat.com (190.red-83-57-173.dynamicip.rima-tde.net. [83.57.173.190]) by smtp.gmail.com with ESMTPSA id k21sm1830660edq.26.2021.01.12.10.36.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 10:36:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4l0kq3wxIJBsGcT12cxU3gmDmz9IWzR6E0aRKmJTUjQ=; b=mFaV7NYmXIn6g4HptlIczJ+2QraPAoku178SziHN3Ki75DJqHBhEvxiMUFN9Db/nBx +hpOdBPj375NjffcD1HiIAs4TLsQpAJ3SS+TswKMivRx88KPUJ9KDomUrY4NOxyYm9OP kkT0DnHoxyD3eW1DWDNDV9rr0qpNuOs0BbiHOSJgWV1M5i1nla/YhnCt/7M4qY777ylt vsU4V9oZXrS4cp5QMIaaIVzk6ftBVMGoMDQO+lq/WvOTP6vZkFIK2a4TuYCpUwyNxT+p KueS7vkMS0OWpht6FpjzH2EztTtYqkHyle3ThJksYEMhKjsC0pu3vmRcOhN5IanM1qDq ooog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=4l0kq3wxIJBsGcT12cxU3gmDmz9IWzR6E0aRKmJTUjQ=; b=XfC/T5uF72a12/C32+UCh/sIroZtIQn1Ry3o6jb7NcGA/huofZb6/oGq6FVSKK69Cv dyKECUodUkGiu4L35D4RCFpVG0FsN0BzT/M+LZO7UiDqL2JnuSIxmQCkZc/HVAjWKL3x UIP4v4d/jJRnunswACbqUtsrObQrcki6RJOLkliwtJ4wKstW7jVUovOg6jX/YOLgjUuS 53jV1bw8bFnLV1L6ZT0CKsxwM1DNhyViRWkn+Rf4VHeDnCIuxoWSfEJKLr2Ed+pk4bmP SzHBdk3vz9dm/XVOPTJCx58ht915HaWDXrj0rdI3TwhbIIWIoBPTlXi27uFXt59m0QA1 DSLA== X-Gm-Message-State: AOAM531vMKbT/tLHfVYhjzU6E7Xe0nmBtGe8Wl7nWVs53Blz7qViyAwQ WqUbJfG4Dj3XeSxFh2e5AoY= X-Google-Smtp-Source: ABdhPJyJun8fhYKMg5tnrCY8tIgZG0kKJ/eXtJ11t71Z3aPw6nE1o0p+5vFfOBCZ9T7InoytwoVgVQ== X-Received: by 2002:a50:fe0e:: with SMTP id f14mr372860edt.159.1610476605633; Tue, 12 Jan 2021 10:36:45 -0800 (PST) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Bin Meng , qemu-devel@nongnu.org, Bin Meng Cc: qemu-arm@nongnu.org, Jean-Christophe Dubois , Peter Maydell , Alistair Francis , Peter Chubb , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [RFC PATCH v6 11/11] hw/ssi: imx_spi: Correct tx and rx fifo endianness Date: Tue, 12 Jan 2021 19:35:29 +0100 Message-Id: <20210112183529.2011863-12-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210112183529.2011863-1-f4bug@amsat.org> References: <20210112183529.2011863-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) From: Bin Meng The endianness of data exchange between tx and rx fifo is incorrect. Earlier bytes are supposed to show up on MSB and later bytes on LSB, ie: in big endian. The manual does not explicitly say this, but the U-Boot and Linux driver codes have a swap on the data transferred to tx fifo and from rx fifo. With this change, U-Boot read from / write to SPI flash tests pass. =3D> sf test 1ff000 1000 SPI flash test: 0 erase: 0 ticks, 4096000 KiB/s 32768.000 Mbps 1 check: 3 ticks, 1333 KiB/s 10.664 Mbps 2 write: 235 ticks, 17 KiB/s 0.136 Mbps 3 read: 2 ticks, 2000 KiB/s 16.000 Mbps Test passed 0 erase: 0 ticks, 4096000 KiB/s 32768.000 Mbps 1 check: 3 ticks, 1333 KiB/s 10.664 Mbps 2 write: 235 ticks, 17 KiB/s 0.136 Mbps 3 read: 2 ticks, 2000 KiB/s 16.000 Mbps Fixes: c906a3a01582 ("i.MX: Add the Freescale SPI Controller") Signed-off-by: Bin Meng Message-Id: <20210112145526.31095-7-bmeng.cn@gmail.com> Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/ssi/imx_spi.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/hw/ssi/imx_spi.c b/hw/ssi/imx_spi.c index c4e2d2e1c97..38892698918 100644 --- a/hw/ssi/imx_spi.c +++ b/hw/ssi/imx_spi.c @@ -176,7 +176,6 @@ static void imx_spi_flush_txfifo(IMXSPIState *s) =20 while (!fifo32_is_empty(&s->tx_fifo)) { int tx_burst =3D 0; - int index =3D 0; =20 if (s->burst_length <=3D 0) { s->burst_length =3D imx_spi_burst_length(s); @@ -197,7 +196,7 @@ static void imx_spi_flush_txfifo(IMXSPIState *s) rx =3D 0; =20 while (tx_burst > 0) { - uint8_t byte =3D tx & 0xff; + uint8_t byte =3D tx >> (tx_burst - 8); =20 DPRINTF("writing 0x%02x\n", (uint32_t)byte); =20 @@ -206,13 +205,11 @@ static void imx_spi_flush_txfifo(IMXSPIState *s) =20 DPRINTF("0x%02x read\n", (uint32_t)byte); =20 - tx =3D tx >> 8; - rx |=3D (byte << (index * 8)); + rx =3D (rx << 8) | byte; =20 /* Remove 8 bits from the actual burst */ tx_burst -=3D 8; s->burst_length -=3D 8; - index++; } =20 DPRINTF("data rx:0x%08x\n", rx); --=20 2.26.2