From nobody Sun Nov 24 04:38:18 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=1726687482; cv=none; d=zohomail.com; s=zohoarc; b=PWg+gP3P6x9DLsX/WqPOkt/OYzKUfsUMCSi00qqvbKIL4b1FPLV4Njc3+dscrgS2xOuqonYGhLBfU6sOMz1DVMUTdhCO1gRq85a347UNE1ihmTjrTjQR7xB1nLhmIyna/qrDzm5KalU5Wci21URBFXJrXOSxMxgLNk45/hZa688= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726687482; 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=mcht1UrN4o7a748za6EPwH1dmZHR+9K1RZ6hCAmN+lI=; b=Ns79CNaWGfoXo3sdX3S0V/qbydM/6FUH8AUtbFynAWHEQoWyP2SSYF2VIxj2XYlO/b5V8r+kVZ+WPZqxB8iet40qdpKJ6w4SNczYQhcoEJFfA7VYEY2+ew9t3RDHM3JqRqaXxkP+0lJG7SKfIJbvQOfbXuX62H538gPFBwMEEv4= 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 1726687482898662.6484559082269; Wed, 18 Sep 2024 12:24:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr0HB-0006Sp-VE; Wed, 18 Sep 2024 15:23:45 -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 <3uSjrZgUKCvQpWrelckkcha.Ykimaiq-Zarahjkjcjq.knc@flex--tavip.bounces.google.com>) id 1sr0H9-0006K9-Rg for qemu-devel@nongnu.org; Wed, 18 Sep 2024 15:23:43 -0400 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3uSjrZgUKCvQpWrelckkcha.Ykimaiq-Zarahjkjcjq.knc@flex--tavip.bounces.google.com>) id 1sr0H8-0007RC-45 for qemu-devel@nongnu.org; Wed, 18 Sep 2024 15:23:43 -0400 Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-206b912491eso12762505ad.0 for ; Wed, 18 Sep 2024 12:23:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726687419; x=1727292219; 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=mcht1UrN4o7a748za6EPwH1dmZHR+9K1RZ6hCAmN+lI=; b=1FSy1Man3j5Q6YQ8ep3L0mHftBs9+R+3qBBAVEASTF9PCbiCUx9J+tHFML4SQ/R1Hj h5YomAbt3sP6Km7IiUvriuxoxqiT0WD7qi+G26Hdwp6TFh17oLz9DayzrgbiV5BqlkL0 CUYFx8iznga4nbfYImdqNzHqv+hBUHtcXLm4X99jaLkB98RVaddIdKOJpiHh5clzKmWB 8Mx5MXU0btX6C66x0ZuFjwwxpwkykr/yeNu7c0yoDamIWuUsw5VSThHH0zR1K8eMArwh 9fwbIC07m2OwEkiP+vfDjaEwT31c/H5HvCZYN+1UKWJyChuCQm/+KAbgBHKdyFInDSo1 T3TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726687419; x=1727292219; 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=mcht1UrN4o7a748za6EPwH1dmZHR+9K1RZ6hCAmN+lI=; b=rufJ0N5Q/W9NLuRGEvb2vWKT98r067kKlWN2GX5DG1hcfsHdk6WN9HfvEHZTPV+7QD JLjK/VINe9hpSI5NHqmIJ38AqUh4nso6h+J91sO6iBAxa7LWtRL6qsa6KAsBQ/URkUYV +GBSnMx2/WEBhr3bRYnOk3EOzovZTC8ZeGk70ECCLuZ0NIfnjuxRPOLuNCFQFOI4oJGO CY6P1NL6QHrhlXSRayBxqDG7lIVQfeEl76fVo1B9FEgzRB0EtVVoPy3apKtoVD53bkf7 uQ5+af1KuanXbJAmz4aUU+MRszdYe9gZrZYZn2QtfNZC8lD0eOh/qZL3TA0fBlkwc6oA BZUA== X-Gm-Message-State: AOJu0Yzh/x6TjU/qANyTmOIK9QqAPyeW1HkalPc+MgnKhF0YmpNXcvaI 6wXCo+bOIcIp01icqO6D2AzNafHiSC3dn7kVUnxd9/qO87x8ZtYw4E3g7XwMw3lqNk2EmnVZOi/ tRsFRKZhpvXgFlin48h3GIvturJGinMzH3hjsxVYhIxAqvQdbg4D54sDofaf69gaW9pnaEAdZ6B NTX/z5n2nx2kSCYfc5KSrjg7UeBg== X-Google-Smtp-Source: AGHT+IFumOnyLqv5J02XQqn8ZjlwZgw+QflJFXmX8qjlVZTiSy/Y/YtmA/2k4SYTA4kmWIIOqKQUJoKluQ== X-Received: from warp10.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:750]) (user=tavip job=sendgmr) by 2002:a17:902:e204:b0:1fb:1658:926 with SMTP id d9443c01a7336-208cc3b9e48mr3785ad.6.1726687417742; Wed, 18 Sep 2024 12:23:37 -0700 (PDT) Date: Wed, 18 Sep 2024 12:22:50 -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-23-tavip@google.com> Subject: [PATCH 22/25] hw/misc: add spi-tester 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::649; envelope-from=3uSjrZgUKCvQpWrelckkcha.Ykimaiq-Zarahjkjcjq.knc@flex--tavip.bounces.google.com; helo=mail-pl1-x649.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: 1726687485137116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a simple SPI peripheral that echoes back received data. Useful for testing SPI controllers. Signed-off-by: Octavian Purdila --- include/hw/misc/spi_tester.h | 32 +++++++++++++++++ hw/misc/spi_tester.c | 67 ++++++++++++++++++++++++++++++++++++ hw/misc/Kconfig | 5 +++ hw/misc/meson.build | 1 + 4 files changed, 105 insertions(+) create mode 100644 include/hw/misc/spi_tester.h create mode 100644 hw/misc/spi_tester.c diff --git a/include/hw/misc/spi_tester.h b/include/hw/misc/spi_tester.h new file mode 100644 index 0000000000..8935f3f1af --- /dev/null +++ b/include/hw/misc/spi_tester.h @@ -0,0 +1,32 @@ +/* + * Simple SPI peripheral device used for SPI controller testing. + * + * 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. + */ + +#ifndef HW_SPI_TESTER_H +#define HW_SPI_TESTER_H + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/bswap.h" +#include "hw/irq.h" +#include "hw/ssi/ssi.h" +#include "qemu/timer.h" +#include "hw/qdev-properties.h" + +#define TYPE_SPI_TESTER "spi-tester" +#define SPI_TESTER(obj) OBJECT_CHECK(SpiTesterState, (obj), TYPE_SPI_TESTE= R) + +typedef struct { + SSIPeripheral ssidev; + bool cs; +} SpiTesterState; + +#endif /* HW_SPI_TESTER_H */ diff --git a/hw/misc/spi_tester.c b/hw/misc/spi_tester.c new file mode 100644 index 0000000000..2793ce52dc --- /dev/null +++ b/hw/misc/spi_tester.c @@ -0,0 +1,67 @@ +/* + * Simple SPI peripheral echo device used for SPI controller testing. + * + * 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 "migration/vmstate.h" +#include "hw/misc/spi_tester.h" + +static uint32_t spi_tester_transfer(SSIPeripheral *dev, uint32_t value) +{ + SpiTesterState *s =3D SPI_TESTER(dev); + + if (s->cs) { + return 0; + } + + return value; +} + +static int spi_tester_set_cs(SSIPeripheral *dev, bool select) +{ + SpiTesterState *s =3D SPI_TESTER(dev); + + s->cs =3D select; + + return 0; +} + +static const VMStateDescription vmstate_spi_tester =3D { + .name =3D "spi-tester", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_SSI_PERIPHERAL(ssidev, SpiTesterState), + VMSTATE_BOOL(cs, SpiTesterState), + VMSTATE_END_OF_LIST() + } +}; + +static void spi_tester_class_init(ObjectClass *klass, void *data) +{ + SSIPeripheralClass *k =3D SSI_PERIPHERAL_CLASS(klass); + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->vmsd =3D &vmstate_spi_tester; + k->transfer =3D spi_tester_transfer; + k->set_cs =3D spi_tester_set_cs; + k->cs_polarity =3D SSI_CS_LOW; +} + +static const TypeInfo spi_tester_types[] =3D { + { + .name =3D TYPE_SPI_TESTER, + .parent =3D TYPE_SSI_PERIPHERAL, + .instance_size =3D sizeof(SpiTesterState), + .class_init =3D spi_tester_class_init, + }, +}; + +DEFINE_TYPES(spi_tester_types); diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig index 3e93c12c8e..484ee3149f 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -218,6 +218,11 @@ config I2C_TESTER default y if TEST_DEVICES depends on I2C =20 +config SPI_TESTER + bool + default y if TEST_DEVICES + depends on SSI + config FLEXCOMM bool select I2C diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 4f22231fa3..413171f379 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -159,6 +159,7 @@ system_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('= sbsa_ec.c')) system_ss.add(when: 'CONFIG_LASI', if_true: files('lasi.c')) =20 system_ss.add(when: 'CONFIG_I2C_TESTER', if_true: files('i2c_tester.c')) +system_ss.add(when: 'CONFIG_SPI_TESTER', if_true: files('spi_tester.c')) =20 system_ss.add(when: 'CONFIG_FLEXCOMM', if_true: files('flexcomm.c')) system_ss.add(when: 'CONFIG_RT500_CLKCTL', if_true: files('rt500_clkctl0.c= ', 'rt500_clkctl1.c')) --=20 2.46.0.662.g92d0881bb0-goog