From nobody Sun Nov 24 05:38:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1726687472; cv=none; d=zohomail.com; s=zohoarc; b=BJpcnMLgTAmQB7fT8pttRQYumYE5n7WWoL60eWmPwYGoKXcoUZyPLugO9yG9vJjTtc+xOzUg4uvi0Zx308n2h7LvBPFhHQSIu98z7/q07N746YZCxuvuNrlHDRdROTQT5k7BcYqCOxCoM48J9SO7PJSAfnHfoj1h2w+MgY2Njxs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726687472; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CWax01LO11cCMxk7XAjv93ylNJE01EbdgJ7/Pszq034=; b=IXpF8k46rle7zgF/S2CXxlCnFmq5oN9Vcggd/Zz7HHO3FSG46R21FPFO7UZw/3+hsQbqQEAud+kPZxP8VS4IpstgsyyX6AedgRegulVwHIZ1CPL5R/4DzFYSKWqcR1lINKV+TLEswub3Y2t8CClmeXcty8zCwYdq9O/yxuob/iA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726687472977775.7146582144322; Wed, 18 Sep 2024 12:24:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr0HE-0006ey-Kb; Wed, 18 Sep 2024 15:23:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3uyjrZgUKCvYrYtgnemmejc.amkocks-bctcjlmlels.mpe@flex--tavip.bounces.google.com>) id 1sr0HB-0006PP-7N for qemu-devel@nongnu.org; Wed, 18 Sep 2024 15:23:45 -0400 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3uyjrZgUKCvYrYtgnemmejc.amkocks-bctcjlmlels.mpe@flex--tavip.bounces.google.com>) id 1sr0H8-0007RO-Uf for qemu-devel@nongnu.org; Wed, 18 Sep 2024 15:23:44 -0400 Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-71985a317fcso50010b3a.1 for ; Wed, 18 Sep 2024 12:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726687421; x=1727292221; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=CWax01LO11cCMxk7XAjv93ylNJE01EbdgJ7/Pszq034=; b=zGhet/009glFKP7BXtgbv4pDmJ7s7lZoJHOGR9GQ4/Vot2oOYiHjsgOtqL5/TIbBmU ptuJTfwQfqUdT18ap8MSeuPEk2+DOMbIo8ZXZG7ZmwoKOzKkID54daYGnvK7yK63JhIp 1PjCIph8Q5GM3zuEuDna9W/Eo1ZproFVfUTApjpLYstL9w3TpV3vcVwey/4jZDVLC/Ka Uxl8/CkqGi9lyHPTpVygHVnEPlGe3XZ8ZMMJZpfOtO3j8ajAq1p2TEyecWKkUlszgcNF wXmyMsbikapeZ3yLsnvjkSOP9K/flc5THw53on4QAQGZ/thABpRqcUEr+0svBiS26oYD xPFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726687421; x=1727292221; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CWax01LO11cCMxk7XAjv93ylNJE01EbdgJ7/Pszq034=; b=pFrUGzgA4YVdIwbPIOMF2PATs6usPRx9qfcM5SDo4ZXfzFe3KnS9nQWV94+5kt0bRd Ud/wD0hzlBtmnIhlb9EDqzNYCybJYDF22tvV/aB+yoAK/laj4/Id8td3E3tZD9MCGjLc is+cp4DM0O5v+TlbuzRl5AjPb73Sn2D/XYXhtSapgAW1ZQsuH4rAEPBw2wwlCbQ4iMGI MOZeEu7n+9BIExzWS1W9+tXbuDJlDrXDeMtXwQTH6vCznZBN9ImV+dXpLegRMvcLo3nr BVL4xmIEYY61UFJOQt0P1Mfrms66gTvW42mtdfAIDcE55m6lXPQ9eVSuK/nU1yiGHUsX a+PA== X-Gm-Message-State: AOJu0Yy83ayf/dDedWxt9C7BkxRdjzWiCDyB6ONneAciIcaMMAoNzyVu mrYBLSmbLKdlSanOPwowvY6BY7mqBEz16mh2jMhOm9bhVLCxbfESB6rwuh6OUejuk6dDbq6iNiD ZXektRNpieXzSj3fzJV5pS3dvDhNqCHvuMO5OL5jWc659AvS9HPDs4E/dw7C4bvs/uJ4GwL3ELo wu+x+cxcEHvZKY/9EQeo6/cDgJ5w== X-Google-Smtp-Source: AGHT+IHvipsDN/lR67gcLqKAQStRGIe/Xifx2ShSlVwhQHbSb87y5XlxAEKzi/jyANlbDjk5JNKAxYhJdA== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a62:aa14:0:b0:717:9798:a8ca with SMTP id d2e1a72fcca58-719262286femr63984b3a.4.1726687419607; Wed, 18 Sep 2024 12:23:39 -0700 (PDT) Date: Wed, 18 Sep 2024 12:22:51 -0700 In-Reply-To: <20240918192254.3136903-1-tavip@google.com> Mime-Version: 1.0 References: <20240918192254.3136903-1-tavip@google.com> X-Mailer: git-send-email 2.46.0.662.g92d0881bb0-goog Message-ID: <20240918192254.3136903-24-tavip@google.com> Subject: [PATCH 23/25] tests/qtest: add tests for flexcomm spi From: Octavian Purdila To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, stefanst@google.com, pbonzini@redhat.com, peter.maydell@linaro.org, marcandre.lureau@redhat.com, berrange@redhat.com, eduardo@habkost.net, luc@lmichel.fr, damien.hedde@dahe.fr, alistair@alistair23.me, thuth@redhat.com, philmd@linaro.org, jsnow@redhat.com, crosa@redhat.com, lvivier@redhat.com Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::44a; envelope-from=3uyjrZgUKCvYrYtgnemmejc.amkocks-bctcjlmlels.mpe@flex--tavip.bounces.google.com; helo=mail-pf1-x44a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1726687475118116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Sebastian Ene Add master and loopback tests for flexcomm spi. Signed-off-by: Sebastian Ene [tavip: add master mode test, convert to qtest] Signed-off-by: Octavian Purdila --- tests/qtest/flexcomm-spi-test.c | 145 ++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 2 +- 2 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/flexcomm-spi-test.c diff --git a/tests/qtest/flexcomm-spi-test.c b/tests/qtest/flexcomm-spi-tes= t.c new file mode 100644 index 0000000000..4658835b8f --- /dev/null +++ b/tests/qtest/flexcomm-spi-test.c @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2024 Google LLC. + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" + +#include "qemu/config-file.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qapi/error.h" +#include "qemu/sockets.h" +#include "sysemu/sysemu.h" +#include "qemu/main-loop.h" +#include "qemu/option.h" +#include "exec/memory.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-core.h" + +#include "hw/misc/flexcomm.h" +#include "hw/arm/svd/flexcomm_spi.h" +#include "hw/arm/svd/rt500.h" +#include "reg-utils.h" + +/* The number of words sent on the SPI in loopback mode. */ +#define SEQ_LOOPBACK_MODE (8) + +/* This value is used to set the cycle counter for the spi tester */ +#define SPI_TESTER_CONFIG (0x10) + +#define FLEXCOMM_BASE RT500_FLEXCOMM0_BASE +#define FLEXCOMM_SPI_BASE RT500_FLEXCOMM0_BASE +#define DEVICE_NAME "/machine/soc/flexcomm0" + +static void configure_spi(bool master, bool is_loopback_mode) +{ + uint32_t tmp; + + /* Select and lock SPI */ + tmp =3D FLEXCOMM_PERSEL_SPI; + FIELD_DP32(tmp, FLEXCOMM_PSELID, LOCK, 1); + REG32_WRITE(FLEXCOMM, PSELID, tmp); + + /* Disable the FIFO */ + REG32_WRITE_FIELD(FLEXCOMM_SPI, CFG, ENABLE, 0); + REG32_WRITE_FIELD(FLEXCOMM_SPI, FIFOCFG, ENABLETX, 0); + REG32_WRITE_FIELD(FLEXCOMM_SPI, FIFOCFG, ENABLERX, 0); + + if (is_loopback_mode) { + /* Set up SPI interface - loop mode, master mode */ + REG32_WRITE_FIELD(FLEXCOMM_SPI, CFG, LOOP, 1); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, CFG, LOOP) =3D=3D 1); + } + + if (master) { + REG32_WRITE_FIELD(FLEXCOMM_SPI, CFG, MASTER, 1); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, CFG, MASTER) =3D=3D 1); + } else { + REG32_WRITE_FIELD(FLEXCOMM_SPI, CFG, MASTER, 0); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, CFG, MASTER) =3D=3D 0); + } + + /* Enable the FIFO */ + REG32_WRITE_FIELD(FLEXCOMM_SPI, FIFOCFG, ENABLETX, 1); + REG32_WRITE_FIELD(FLEXCOMM_SPI, FIFOCFG, ENABLERX, 1); + + /* Enable the SPI */ + REG32_WRITE_FIELD(FLEXCOMM_SPI, CFG, ENABLE, 1); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, CFG, ENABLE) =3D=3D 1); +} + +/* The SPI controller running in master mode can run in loopback mode for = */ +/* internal testing. Transmit and receive lines are connected together. */ +static void loopback_test(gconstpointer user_data) +{ + configure_spi(true, true); + + /* Write a sequence */ + for (int i =3D 0; i < SEQ_LOOPBACK_MODE; i++) { + REG32_WRITE(FLEXCOMM_SPI, FIFOWR, i); + } + + /* Read the sequence back */ + for (int i =3D 0; i < SEQ_LOOPBACK_MODE; i++) { + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, FIFORD, RXDATA) =3D=3D i); + } +} + +static void master_test(gconstpointer user_data) +{ + uint32_t tmp; + + configure_spi(true, false); + + REG32_WRITE_FIELD(FLEXCOMM_SPI, CFG, LSBF, 1); + + /* single 16bit word transfer */ + + tmp =3D FIELD_DP32(0x1122, FLEXCOMM_SPI_FIFOWR, EOT, 1); + tmp =3D FIELD_DP32(tmp, FLEXCOMM_SPI_FIFOWR, TXSSEL0_N, 1); + tmp =3D FIELD_DP32(tmp, FLEXCOMM_SPI_FIFOWR, LEN, 0xF); + REG32_WRITE(FLEXCOMM_SPI, FIFOWR, tmp); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, FIFOSTAT, RXNOTEMPTY) =3D=3D 1= ); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_SPI, FIFORD, RXDATA), + =3D=3D, 0x1122); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, FIFOSTAT, RXNOTEMPTY) =3D=3D 0= ); + + /* multi word 8 bits transfer */ + + tmp =3D FIELD_DP32(0x11, FLEXCOMM_SPI_FIFOWR, TXSSEL0_N, 1); + tmp =3D FIELD_DP32(tmp, FLEXCOMM_SPI_FIFOWR, LEN, 0x7); + REG32_WRITE(FLEXCOMM_SPI, FIFOWR, tmp); + tmp =3D 0x22; + FIELD_DP32(tmp, FLEXCOMM_SPI_FIFOWR, EOT, 1); + FIELD_DP32(tmp, FLEXCOMM_SPI_FIFOWR, TXSSEL0_N, 1); + FIELD_DP32(tmp, FLEXCOMM_SPI_FIFOWR, LEN, 0x7); + REG32_WRITE(FLEXCOMM_SPI, FIFOWR, tmp); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, FIFOSTAT, RXNOTEMPTY) =3D=3D 1= ); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, FIFORD, RXDATA) =3D=3D 0x11); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, FIFOSTAT, RXNOTEMPTY) =3D=3D 1= ); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, FIFORD, RXDATA) =3D=3D 0x22); + g_assert(REG32_READ_FIELD(FLEXCOMM_SPI, FIFOSTAT, RXNOTEMPTY) =3D=3D 0= ); +} + +int main(int argc, char **argv) +{ + int ret; + + module_call_init(MODULE_INIT_QOM); + g_test_init(&argc, &argv, NULL); + + qtest_add_data_func("/flexcomm-spi/loopack", NULL, loopback_test); + qtest_add_data_func("/flexcomm-spi/master", NULL, master_test); + + qtest_start("-M rt595-evk -device spi-tester,bus=3D/flexcomm0-spi"); + ret =3D g_test_run(); + qtest_end(); + + return ret; +} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 74fef28551..2cb0fa08c0 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -231,7 +231,7 @@ qtests_arm =3D \ (config_all_devices.has_key('CONFIG_FSI_APB2OPB_ASPEED') ? ['aspeed_fsi-= test'] : []) + \ (config_all_devices.has_key('CONFIG_STM32L4X5_SOC') and config_all_devices.has_key('CONFIG_DM163')? ['dm163-test'] : []) + \ - (config_all_devices.has_key('CONFIG_FLEXCOMM') ? ['flexcomm-test', 'flex= comm-usart-test', 'flexcomm-i2c-test'] : []) + \ + (config_all_devices.has_key('CONFIG_FLEXCOMM') ? ['flexcomm-test', 'flex= comm-usart-test', 'flexcomm-i2c-test', 'flexcomm-spi-test'] : []) + \ ['arm-cpu-features', 'boot-serial-test'] =20 --=20 2.46.0.662.g92d0881bb0-goog