From nobody Tue Nov 26 10:39:00 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1708806292; cv=none; d=zohomail.com; s=zohoarc; b=jRnDFbX8cX0/fwAMdtwSMiv768GiZpEYJjtX9/6l7GAKu30sCTew6fIo51iU1S8YIP5hiea9ORGa91ZS6V/Vg+kqjs9Tp50CPnm9UD2oeppgj4Krw7H3U/EurwVyyFUYjnuE2iRgZIZ1m5YJcOYYVsajvPcLowa27b4Dfz9DJs8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708806292; h=Content-Transfer-Encoding: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=13OHCQV4gOWKyRBUqNbkx8gEZsa9oMxaeAkREwVQxP4=; b=UBTpvjM4THHD50wEnkdU/0lcm1QU9Tc1nbXA983FJxi9cGqCh3dU/Ma4LWzVW15qcQLe38JBOOKObEN7UxYRE4wZ/naPSFvamFmLaXhFXi4TxnUd17xCWgNdeBF6PPzqM2Rd+hkZcMyujnsdzrSAQgJNbMqV9OdOM30DldPUGL0= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708806292533132.49410104717822; Sat, 24 Feb 2024 12:24:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdyYh-00070A-1d; Sat, 24 Feb 2024 15:23:43 -0500 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 ) id 1rdyYf-0006zX-BO; Sat, 24 Feb 2024 15:23:41 -0500 Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdyYc-0004Ip-LH; Sat, 24 Feb 2024 15:23:41 -0500 Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2d275e63590so17637671fa.2; Sat, 24 Feb 2024 12:23:37 -0800 (PST) Received: from localhost.localdomain ([212.70.108.232]) by smtp.gmail.com with ESMTPSA id g2-20020a50ee02000000b00560c6ff443esm816108eds.66.2024.02.24.12.23.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 12:23:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708806216; x=1709411016; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=13OHCQV4gOWKyRBUqNbkx8gEZsa9oMxaeAkREwVQxP4=; b=FgD7iL8QT1SC2XqbqY9ZgXGCjauPR+wOG0Fr+mBIVjlYgBRLu8528s2Ug1NflhH2LL Re2XmYl6fp+LdVEdRhvbFGg5wuWzneKCv4+QXRmr00EiwIO68ggu79gn7ajZSXoT3ah9 IqVl2lXyD3FDNIsVZQNpw6wtD39pv9ul/k6DSv+6CVjeuZzf1W8dVe4KOz0uJvvuj3fR eB9uz90kop3b77JijPJi5Nl8bbLHDQw6I4nD3pPQeO61bmtu3enKVUMaHe0VGqKmczcy lze1A+4N+F/FkEE+i2xa6o22ez6VYFYqzpfuk8FbpB3/P/s4KNqpfJ38+YVbTliiuSLW R/eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708806216; x=1709411016; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=13OHCQV4gOWKyRBUqNbkx8gEZsa9oMxaeAkREwVQxP4=; b=DHC06W8IVL4EYLtcTN6W33nkGeN2LJI5r7+F5eVjuvk9ehiOhIVMC0EMlnPxqIxqP5 8pgW4mAwmX5XFyiJdmRxFSmAx4E/T3hnrlvOlWvBcMdq8i9tGeloi3VjDsX5TRVIQoGQ hWFb2SBgBJU4tRMj06lYRsi3MEMxEqHhtkaQ049yOwBFxafUi90nXLbIyxYQAJMoVGhI Sm8ZHGBpTfVsWvbUe7TtiuMdyHHH8AmpPBEhVuDwO6rRBDAvb6c6cAqW8sK3yi0BLp8h gxeH4nF58BcG64FjT2mj++1P4XPnMgiphy/wjeapyv7Idk5KranM7WxqEqRcg//im7/M hU6w== X-Forwarded-Encrypted: i=1; AJvYcCV0+7URes1BpHbyqPZLPak0nyd9ulroZyNxWk8AO9wZ7okYi23Tsw1TUdsLM9tlo5/U4Sy6UxcKx0EeXN4VBrqTPyYF X-Gm-Message-State: AOJu0YyX7zBplS6dlgZbWthw6larnt7EXZuGvKm2ECz4gJq6LVyJcwTL rBgd+GxMw8zjnYbaW5TnOthXIAha8Z8AG1VfPP9Krxwlk6nH4dcGWYQuKb0X X-Google-Smtp-Source: AGHT+IFxjdgV/9bqZaXgoPBszbC+xbRl9bDMtlb5l0nYS/ZB2+X6Zt+KmiH8Aed/c1UnysjVoCbltg== X-Received: by 2002:a2e:8552:0:b0:2d2:7f28:7fdd with SMTP id u18-20020a2e8552000000b002d27f287fddmr1035012ljj.52.1708806215742; Sat, 24 Feb 2024 12:23:35 -0800 (PST) From: Rayhan Faizel To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, philmd@linaro.org, pbonzini@redhat.com, qemu-arm@nongnu.org, Rayhan Faizel , Thomas Huth , Laurent Vivier Subject: [PATCH v4 3/3] tests/qtest: Add testcase for BCM2835 BSC Date: Sun, 25 Feb 2024 00:32:45 +0530 Message-Id: <20240224190245.2405016-4-rayhan.faizel@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240224190245.2405016-1-rayhan.faizel@gmail.com> References: <20240224190245.2405016-1-rayhan.faizel@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::231; envelope-from=rayhan.faizel@gmail.com; helo=mail-lj1-x231.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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 @gmail.com) X-ZM-MESSAGEID: 1708806294265100008 Content-Type: text/plain; charset="utf-8" Simple testcase for validating proper operation of read and write for all three BSC controllers. Signed-off-by: Rayhan Faizel Reviewed-by: Peter Maydell --- tests/qtest/bcm2835-i2c-test.c | 115 +++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 2 +- 2 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/bcm2835-i2c-test.c diff --git a/tests/qtest/bcm2835-i2c-test.c b/tests/qtest/bcm2835-i2c-test.c new file mode 100644 index 0000000000..513ecce61d --- /dev/null +++ b/tests/qtest/bcm2835-i2c-test.c @@ -0,0 +1,115 @@ +/* + * QTest testcase for Broadcom Serial Controller (BSC) + * + * Copyright (c) 2024 Rayhan Faizel + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "libqtest-single.h" + +#include "hw/i2c/bcm2835_i2c.h" +#include "hw/sensor/tmp105_regs.h" + +static const uint32_t bsc_base_addrs[] =3D { + 0x3f205000, /* I2C0 */ + 0x3f804000, /* I2C1 */ + 0x3f805000, /* I2C2 */ +}; + +static void bcm2835_i2c_init_transfer(uint32_t base_addr, bool read) +{ + /* read flag is bit 0 so we can write it directly */ + int interrupt =3D read ? BCM2835_I2C_C_INTR : BCM2835_I2C_C_INTT; + + writel(base_addr + BCM2835_I2C_C, + BCM2835_I2C_C_I2CEN | BCM2835_I2C_C_INTD | + BCM2835_I2C_C_ST | BCM2835_I2C_C_CLEAR | interrupt | read); +} + +static void test_i2c_read_write(gconstpointer data) +{ + uint32_t i2cdata; + intptr_t index =3D (intptr_t) data; + uint32_t base_addr =3D bsc_base_addrs[index]; + + /* Write to TMP105 register */ + writel(base_addr + BCM2835_I2C_A, 0x50); + writel(base_addr + BCM2835_I2C_DLEN, 3); + + bcm2835_i2c_init_transfer(base_addr, 0); + + writel(base_addr + BCM2835_I2C_FIFO, TMP105_REG_T_HIGH); + writel(base_addr + BCM2835_I2C_FIFO, 0xde); + writel(base_addr + BCM2835_I2C_FIFO, 0xad); + + /* Clear flags */ + writel(base_addr + BCM2835_I2C_S, BCM2835_I2C_S_DONE | BCM2835_I2C_S_E= RR | + BCM2835_I2C_S_CLKT); + + /* Read from TMP105 register */ + writel(base_addr + BCM2835_I2C_A, 0x50); + writel(base_addr + BCM2835_I2C_DLEN, 1); + + bcm2835_i2c_init_transfer(base_addr, 0); + + writel(base_addr + BCM2835_I2C_FIFO, TMP105_REG_T_HIGH); + + writel(base_addr + BCM2835_I2C_DLEN, 2); + bcm2835_i2c_init_transfer(base_addr, 1); + + i2cdata =3D readl(base_addr + BCM2835_I2C_FIFO); + g_assert_cmpint(i2cdata, =3D=3D, 0xde); + + i2cdata =3D readl(base_addr + BCM2835_I2C_FIFO); + g_assert_cmpint(i2cdata, =3D=3D, 0xad); + + /* Clear flags */ + writel(base_addr + BCM2835_I2C_S, BCM2835_I2C_S_DONE | BCM2835_I2C_S_E= RR | + BCM2835_I2C_S_CLKT); + +} + +int main(int argc, char **argv) +{ + int ret; + int i; + + g_test_init(&argc, &argv, NULL); + + for (i =3D 0; i < 3; i++) { + g_autofree char *test_name =3D + g_strdup_printf("/bcm2835/bcm2835-i2c%d/read_write", i); + qtest_add_data_func(test_name, (void *)(intptr_t) i, + test_i2c_read_write); + } + + /* Run I2C tests with TMP105 slaves on all three buses */ + qtest_start("-M raspi3b " + "-device tmp105,address=3D0x50,bus=3Di2c-bus.0 " + "-device tmp105,address=3D0x50,bus=3Di2c-bus.1 " + "-device tmp105,address=3D0x50,bus=3Di2c-bus.2"); + ret =3D g_test_run(); + qtest_end(); + + return ret; +} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 39557d5ecb..8fe303160e 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -228,7 +228,7 @@ qtests_aarch64 =3D \ ['tpm-tis-device-test', 'tpm-tis-device-swtpm-test'] : []) + = \ (config_all_devices.has_key('CONFIG_XLNX_ZYNQMP_ARM') ? ['xlnx-can-test'= , 'fuzz-xlnx-dp-test'] : []) + \ (config_all_devices.has_key('CONFIG_XLNX_VERSAL') ? ['xlnx-canfd-test', = 'xlnx-versal-trng-test'] : []) + \ - (config_all_devices.has_key('CONFIG_RASPI') ? ['bcm2835-dma-test'] : [])= + \ + (config_all_devices.has_key('CONFIG_RASPI') ? ['bcm2835-dma-test', 'bcm2= 835-i2c-test'] : []) + \ (config_all_accel.has_key('CONFIG_TCG') and = \ config_all_devices.has_key('CONFIG_TPM_TIS_I2C') ? ['tpm-tis-i2c-test']= : []) + \ (config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \ --=20 2.34.1