From nobody Wed Dec 17 03:45:25 2025 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=1765409487; cv=none; d=zohomail.com; s=zohoarc; b=LAtHzsVPCBvEBSqlvcJcd4LDniatp1a2927wqo4E/kqkNiPfsDRdtifWXclCLAMB/ENOE74fIyP+yRZFQcfC3RoT0xzcCEwoaijEBL9jKzeiab8s5Pgsm1Pz5lCHBuKN/+gyWyIjo5dz/B5AKI+7CQQoZ5Sec0wgUE9oaqvYHtE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765409487; 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=ZyvCNr9C3UGTFli2plhPAot4Fd96bBiVyI7hXjBJHEU=; b=OhEYMRtyAPEB5Yc/PQYXve72DLbmWDKwcF4FM6bHV9ZK/jwRx8Xfk1bSza5m+1Q7DeLroeb6c0sEJ5+Olro0J93Wb6hyI2rQH3v5Y01JgUKOli2gy/kjFPUMcDfnKGeTEVSHREvErFN0PE1JSHiipKn3jM5NFF2PY01LG2nqE/E= 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 176540948786237.57887144515405; Wed, 10 Dec 2025 15:31:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTTcu-000484-Fl; Wed, 10 Dec 2025 18:29:44 -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 <3YAI6aQYKCp0VR8FKWDLLDIB.9LJNBJR-ABSBIKLKDKR.LOD@flex--yubinz.bounces.google.com>) id 1vTTcr-000462-IG for qemu-devel@nongnu.org; Wed, 10 Dec 2025 18:29:41 -0500 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3YAI6aQYKCp0VR8FKWDLLDIB.9LJNBJR-ABSBIKLKDKR.LOD@flex--yubinz.bounces.google.com>) id 1vTTcp-0005hD-Iz for qemu-devel@nongnu.org; Wed, 10 Dec 2025 18:29:41 -0500 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-c0bead25feeso294509a12.0 for ; Wed, 10 Dec 2025 15:29:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765409376; x=1766014176; 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=ZyvCNr9C3UGTFli2plhPAot4Fd96bBiVyI7hXjBJHEU=; b=Wn6LhA8zl42s0UjtM034M07TYtys1gRN00Y1l1JnZuYZ7R/+E3YLVzRlefu3h8H9/8 +E5bXL30dIk0cxUTd4kzPwfee5CqsPsVycO24E1Nn/f7ZsyqeFVLHbu3IbYxWftDz3Gm 6jeZB2OKpRo1Trlyqn9heVD4IMOxErzJ6M5waFvxgNytHEmFdSG31D+0iXBgla0PQNOL KTR8emCgh6zn3fI9hMve7nq5/W63IDWL+LUmUNuOyUhKpEfdB4EdLuqTOa+HGWV/h6t0 Hzzu3vjflr0W8x5lGJPlu6UlWQr5SgnnZcpHDa5ADGbApEyoSNEYVGfRYudHvLMZ7XG9 F4Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765409376; x=1766014176; 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=ZyvCNr9C3UGTFli2plhPAot4Fd96bBiVyI7hXjBJHEU=; b=KEJIGe8rcE8AJWg9+/MeO4Vkf24z7TjIUWC/gZsv9xtFLQNwEfG4fjZx7jcm3BNMe2 BCSwyeQkSQPQIeMtR9/oruKANN0t8ydvY+Ix9iWbaOO8IxbQnTNq2a6yITT+3+7xJ1IK 58Dd6h1eafOfeCk8ivvmNhiVTfvj2oVkIT2XFVidsjWn+hJt+hFS/u8KzdRpf0SWI7aM x/YvoOIdL/FTbj64dTFjpvzPZ45ha9ey2K56rvSRTuNdDGd8qlxpo7DPN6vk03c6X3ig g0lIBjYRsfQ9wCKefP9P/qGJhFLaV5jpiXwPp4wgsEkbG1xahpv06SuqAtYiCAPlJYGQ Wg1A== X-Gm-Message-State: AOJu0YwjOw+r6lpnFteDK3pcTLsUaQBP/soiR261ZOshOOCBjpzPujyi bz7OsEde8y+fpbchfv/zn0MUlOiNuapWRhdH2B82QYLyCPIuAJi0mO7A1YBWJ4NmLGh+qIWM+nf sfUBLdoM4W9aCXJuVacZfDiDo6YWdNpEEYOmY2z3ifGkHjWsDyXoZu7wiVskC2ziVFoo7ssHXAV Oo+gaq1nfTTUwO9VijBYLvtfE6fQ8YOWpae2c= X-Google-Smtp-Source: AGHT+IHH1HO8ZTedPI5SCflCTgNCjanxooAyRmN2R8zPvFeLAmEOHdG46JrOggCoQQy0y9s/KKp9Ocep/24= X-Received: from dyz15.prod.google.com ([2002:a05:693c:408f:b0:2a2:4eb1:3771]) (user=yubinz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:ac83:b0:2a4:3593:4684 with SMTP id 5a478bee46e88-2ac0569c99emr4353436eec.32.1765409376176; Wed, 10 Dec 2025 15:29:36 -0800 (PST) Date: Wed, 10 Dec 2025 23:29:12 +0000 In-Reply-To: <20251210-aspeed-sgpio-v3-0-eb8b0cf3dd51@google.com> Mime-Version: 1.0 References: <20251210-aspeed-sgpio-v3-0-eb8b0cf3dd51@google.com> X-Mailer: b4 0.14.2 Message-ID: <20251210-aspeed-sgpio-v3-1-eb8b0cf3dd51@google.com> Subject: [PATCH v3 1/6] hw/gpio/aspeed_sgpio: Add basic device model for Aspeed SGPIO From: Yubin Zou To: qemu-devel@nongnu.org Cc: "=?utf-8?q?C=C3=A9dric_Le_Goater?=" , Peter Maydell , Steven Lee , Troy Lee , Jamin Lin , Andrew Jeffery , Joel Stanley , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , Kane-Chen-AS , Nabih Estefan , qemu-arm@nongnu.org, Yubin Zou Content-Type: text/plain; charset="utf-8" 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::549; envelope-from=3YAI6aQYKCp0VR8FKWDLLDIB.9LJNBJR-ABSBIKLKDKR.LOD@flex--yubinz.bounces.google.com; helo=mail-pg1-x549.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: 1765409488836158500 Content-Transfer-Encoding: quoted-printable This initial implementation includes the basic device structure, memory-mapped register definitions, and read/write handlers for the SGPIO control registers. Signed-off-by: Yubin Zou --- include/hw/gpio/aspeed_sgpio.h | 66 ++++++++++++++++++ hw/gpio/aspeed_sgpio.c | 154 +++++++++++++++++++++++++++++++++++++= ++++ hw/gpio/meson.build | 1 + 3 files changed, 221 insertions(+) diff --git a/include/hw/gpio/aspeed_sgpio.h b/include/hw/gpio/aspeed_sgpio.h new file mode 100644 index 0000000000000000000000000000000000000000..ffdc54a112da8962a7bc5773d52= 4f1d86eb85d39 --- /dev/null +++ b/include/hw/gpio/aspeed_sgpio.h @@ -0,0 +1,66 @@ +/* + * ASPEED Serial GPIO Controller + * + * Copyright 2025 Google LLC. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef ASPEED_SGPIO_H +#define ASPEED_SGPIO_H + +#include "hw/sysbus.h" +#include "qom/object.h" +#include "hw/registerfields.h" + +#define TYPE_ASPEED_SGPIO "aspeed.sgpio" +OBJECT_DECLARE_TYPE(AspeedSGPIOState, AspeedSGPIOClass, ASPEED_SGPIO) + +#define ASPEED_SGPIO_MAX_PIN_PAIR 256 +#define ASPEED_SGPIO_MAX_INT 8 + +/* AST2700 SGPIO Register Address Offsets */ +REG32(SGPIO_INT_STATUS_0, 0x40) +REG32(SGPIO_INT_STATUS_1, 0x44) +REG32(SGPIO_INT_STATUS_2, 0x48) +REG32(SGPIO_INT_STATUS_3, 0x4C) +REG32(SGPIO_INT_STATUS_4, 0x50) +REG32(SGPIO_INT_STATUS_5, 0x54) +REG32(SGPIO_INT_STATUS_6, 0x58) +REG32(SGPIO_INT_STATUS_7, 0x5C) +/* AST2700 SGPIO_0 - SGPIO_255 Control Register */ +REG32(SGPIO_0_CONTROL, 0x80) + SHARED_FIELD(SGPIO_SERIAL_OUT_VAL, 0, 1) + SHARED_FIELD(SGPIO_PARALLEL_OUT_VAL, 1, 1) + SHARED_FIELD(SGPIO_INT_EN, 2, 1) + SHARED_FIELD(SGPIO_INT_TYPE, 3, 3) + SHARED_FIELD(SGPIO_RESET_POLARITY, 6, 1) + SHARED_FIELD(SGPIO_RESERVED_1, 7, 2) + SHARED_FIELD(SGPIO_INPUT_MASK, 9, 1) + SHARED_FIELD(SGPIO_PARALLEL_EN, 10, 1) + SHARED_FIELD(SGPIO_PARALLEL_IN_MODE, 11, 1) + SHARED_FIELD(SGPIO_INT_STATUS, 12, 1) + SHARED_FIELD(SGPIO_SERIAL_IN_VAL, 13, 1) + SHARED_FIELD(SGPIO_PARALLEL_IN_VAL, 14, 1) + SHARED_FIELD(SGPIO_RESERVED_2, 15, 12) + SHARED_FIELD(SGPIO_WRITE_PROTECT, 31, 1) +REG32(SGPIO_255_CONTROL, 0x47C) + +struct AspeedSGPIOClass { + SysBusDevice parent_obj; + uint32_t nr_sgpio_pin_pairs; + uint64_t mem_size; + const MemoryRegionOps *reg_ops; +}; + +struct AspeedSGPIOState { + /* */ + SysBusDevice parent; + + /*< public >*/ + MemoryRegion iomem; + qemu_irq irq; + uint32_t ctrl_regs[ASPEED_SGPIO_MAX_PIN_PAIR]; + uint32_t int_regs[ASPEED_SGPIO_MAX_INT]; +}; + +#endif /* ASPEED_SGPIO_H */ diff --git a/hw/gpio/aspeed_sgpio.c b/hw/gpio/aspeed_sgpio.c new file mode 100644 index 0000000000000000000000000000000000000000..8676fa7ced134f1f62dc9e30b42= c5fe6db3de268 --- /dev/null +++ b/hw/gpio/aspeed_sgpio.c @@ -0,0 +1,154 @@ +/* + * ASPEED Serial GPIO Controller + * + * Copyright 2025 Google LLC. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/host-utils.h" +#include "qemu/log.h" +#include "qemu/error-report.h" +#include "qapi/error.h" +#include "qapi/visitor.h" +#include "hw/qdev-properties.h" +#include "hw/gpio/aspeed_sgpio.h" + +static uint64_t aspeed_sgpio_2700_read_int_status_reg(AspeedSGPIOState *s, + uint32_t reg) +{ + return 0; +} + +static uint64_t aspeed_sgpio_2700_read_control_reg(AspeedSGPIOState *s, + uint32_t reg) +{ + AspeedSGPIOClass *agc =3D ASPEED_SGPIO_GET_CLASS(s); + uint32_t idx =3D reg - R_SGPIO_0_CONTROL; + if (idx >=3D agc->nr_sgpio_pin_pairs) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: pin index: %d, out of bounds\n= ", + __func__, idx); + return 0; + } + return s->ctrl_regs[idx]; +} + +static void aspeed_sgpio_2700_write_control_reg(AspeedSGPIOState *s, + uint32_t reg, uint64_t data) +{ + AspeedSGPIOClass *agc =3D ASPEED_SGPIO_GET_CLASS(s); + uint32_t idx =3D reg - R_SGPIO_0_CONTROL; + if (idx >=3D agc->nr_sgpio_pin_pairs) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: pin index: %d, out of bounds\n= ", + __func__, idx); + return; + } + s->ctrl_regs[idx] =3D data; +} + +static uint64_t aspeed_sgpio_2700_read(void *opaque, hwaddr offset, + uint32_t size) +{ + AspeedSGPIOState *s =3D ASPEED_SGPIO(opaque); + uint64_t value =3D 0; + uint64_t reg; + + reg =3D offset >> 2; + + switch (reg) { + case R_SGPIO_INT_STATUS_0 ... R_SGPIO_INT_STATUS_7: + aspeed_sgpio_2700_read_int_status_reg(s, reg); + break; + case R_SGPIO_0_CONTROL ... R_SGPIO_255_CONTROL: + value =3D aspeed_sgpio_2700_read_control_reg(s, reg); + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: no getter for offset 0x%" + PRIx64"\n", __func__, offset); + return 0; + } + + return value; +} + +static void aspeed_sgpio_2700_write(void *opaque, hwaddr offset, uint64_t = data, + uint32_t size) +{ + AspeedSGPIOState *s =3D ASPEED_SGPIO(opaque); + uint64_t reg; + + reg =3D offset >> 2; + + switch (reg) { + case R_SGPIO_0_CONTROL ... R_SGPIO_255_CONTROL: + aspeed_sgpio_2700_write_control_reg(s, reg, data); + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: no setter for offset 0x%" + PRIx64"\n", __func__, offset); + return; + } +} + +static const MemoryRegionOps aspeed_gpio_2700_ops =3D { + .read =3D aspeed_sgpio_2700_read, + .write =3D aspeed_sgpio_2700_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid.min_access_size =3D 4, + .valid.max_access_size =3D 4, +}; + +static void aspeed_sgpio_realize(DeviceState *dev, Error **errp) +{ + AspeedSGPIOState *s =3D ASPEED_SGPIO(dev); + SysBusDevice *sbd =3D SYS_BUS_DEVICE(dev); + AspeedSGPIOClass *agc =3D ASPEED_SGPIO_GET_CLASS(s); + + /* Interrupt parent line */ + sysbus_init_irq(sbd, &s->irq); + + memory_region_init_io(&s->iomem, OBJECT(s), agc->reg_ops, s, + TYPE_ASPEED_SGPIO, agc->mem_size); + + sysbus_init_mmio(sbd, &s->iomem); +} + +static void aspeed_sgpio_class_init(ObjectClass *klass, const void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->realize =3D aspeed_sgpio_realize; + dc->desc =3D "Aspeed SGPIO Controller"; +} + +static void aspeed_sgpio_2700_class_init(ObjectClass *klass, const void *d= ata) +{ + AspeedSGPIOClass *agc =3D ASPEED_SGPIO_CLASS(klass); + agc->nr_sgpio_pin_pairs =3D 256; + agc->mem_size =3D 0x1000; + agc->reg_ops =3D &aspeed_gpio_2700_ops; +} + +static const TypeInfo aspeed_sgpio_info =3D { + .name =3D TYPE_ASPEED_SGPIO, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(AspeedSGPIOState), + .class_size =3D sizeof(AspeedSGPIOClass), + .class_init =3D aspeed_sgpio_class_init, + .abstract =3D true, +}; + +static const TypeInfo aspeed_sgpio_ast2700_info =3D { + .name =3D TYPE_ASPEED_SGPIO "-ast2700", + .parent =3D TYPE_ASPEED_SGPIO, + .class_init =3D aspeed_sgpio_2700_class_init, +}; + +static void aspeed_sgpio_register_types(void) +{ + type_register_static(&aspeed_sgpio_info); + type_register_static(&aspeed_sgpio_ast2700_info); +} + +type_init(aspeed_sgpio_register_types); diff --git a/hw/gpio/meson.build b/hw/gpio/meson.build index 74840619c01bf4d9a02c058c434c3ec9d2a55bee..6a67ee958faace69ffd3fe08e8a= de31ced0faf7e 100644 --- a/hw/gpio/meson.build +++ b/hw/gpio/meson.build @@ -16,5 +16,6 @@ system_ss.add(when: 'CONFIG_RASPI', if_true: files( )) system_ss.add(when: 'CONFIG_STM32L4X5_SOC', if_true: files('stm32l4x5_gpio= .c')) system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c')) +system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_sgpio.c')) system_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c')) system_ss.add(when: 'CONFIG_PCF8574', if_true: files('pcf8574.c')) --=20 2.52.0.239.gd5f0c6e74e-goog From nobody Wed Dec 17 03:45:25 2025 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=1765409420; cv=none; d=zohomail.com; s=zohoarc; b=YJBSLI3dF83jXf1Bfu1JbIthbWUh5jp1ggsfppgo8DPn49p4A5AJTne3pB1YFCe9L2pmBo3Tipd0xVyg2J81imPsR0/oD0NBFhS1KlnpMpiHbJR4XAKeVSY/JKXGE+kfBVXJnV/kHVaEri/dtKv9OcJW2DcD4Jk5aH+BmF0RNd0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765409420; 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=zDfTc10h+sN6Hw4TsR9A/uoTVOWxiNQn/0DS/fxireU=; b=bCrx5EmLoxUSHEnrj/JXOYFszu9BszVIFkxAyaAd0pdpbvLc6SlzBXnptg1eysKLV8on7WDlnAa/6ooBCRK3VanfswaGVqEDzoJNvWuZ1MrwGyfMjtqkLbpxy6kszl9NefAqcyraTp9f9wtO+LKAIlB6BzLJOGKUD5zjfxLDTcE= 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 1765409420898887.1811367276798; Wed, 10 Dec 2025 15:30:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTTcw-00048T-If; Wed, 10 Dec 2025 18:29:46 -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 <3YQI6aQYKCp4WS9GLXEMMEJC.AMKOCKS-BCTCJLMLELS.MPE@flex--yubinz.bounces.google.com>) id 1vTTcs-00046Q-0P for qemu-devel@nongnu.org; Wed, 10 Dec 2025 18:29:42 -0500 Received: from mail-dl1-x124a.google.com ([2607:f8b0:4864:20::124a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3YQI6aQYKCp4WS9GLXEMMEJC.AMKOCKS-BCTCJLMLELS.MPE@flex--yubinz.bounces.google.com>) id 1vTTcq-0005hQ-7e for qemu-devel@nongnu.org; Wed, 10 Dec 2025 18:29:41 -0500 Received: by mail-dl1-x124a.google.com with SMTP id a92af1059eb24-11bd7a827fdso2064272c88.1 for ; Wed, 10 Dec 2025 15:29:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765409378; x=1766014178; 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=zDfTc10h+sN6Hw4TsR9A/uoTVOWxiNQn/0DS/fxireU=; b=uF9kllZOqOp/Comx5tOjOE4cXg+snTlUJt4pZkuCMCL0j1kqutuZLTOfL8zbNJRjY7 kGgTVAZPRZfYc7nOxX+DYXbkx6yHq+PNXzpI41xARmqqlvrAohC/EtD9qFI+a+Gf9tIh 6TCxS5RW2k6HKOyDmi+dxGW0cgSllJBqElgee7DDiLk/MNuidAnkc4vRUwV+voaVZazL l64Tnu523RAvSf3NFnyzPPbpd6+NEgCFzvvC/3WrbFnZ93Js6WWFPqENmBfYvmSNtJsv /06mDxHzm3YXvY297//APD/3TIzJpvtPl/x2broGOGSW9hrROYceXbfV9gaAMgyCkOnp fo+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765409378; x=1766014178; 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=zDfTc10h+sN6Hw4TsR9A/uoTVOWxiNQn/0DS/fxireU=; b=d8P7igbntwPVWmyGnSn6W3Limba7Ed5+XErKq5hTc/DeHoonEaIOTbC57cIjtWJ8Zz RroeJ3DYhzYgNJWjpztsJcYukYcNNysqvS7Ro6Hsu6PzpM6NdwnrGrMMhIoeXsSBAIUb VtAwO+obnba3Bm4R/dkIUJwjCkxNDF619xD54U3TsJ4rsSct8eBQmDmYsAT5fQZ/SE/t 9x9o/b3IrvaBjWtNTAO+VxH4ZVsF67dNrxkTlCaqHQ9m5r4VUtS0ys2ugWuyYM08doNo wcqm+t7glGP/qXBSye9YA7oXgi4snRR+vVuF+cORpYQkEJbfPdrgvY3lKq0wjOFvAA8b GV/Q== X-Gm-Message-State: AOJu0YwASs0vqt56MqKmUi0gCQP7kKEZlRyaHCUxTLSbRY+ZJK72qx5p j6vsXyzNi4jznaE3+sCwZo05wnypIrwcTh7/7xlkyr9hOLxzOWqYOqZkO9TBtdmu5UGJOtCXsTH HgAj0CoqSyqCyU8RxQzFddaKHG43KPsp59El2yuxV3oapdC0eWkbd6gbDiCeCUe/Gpz8yLSAxxT 9L9QoY8CnpOq92w7gnIwCjit6+63R8tAdtNfk= X-Google-Smtp-Source: AGHT+IEMhUFqF7UGlgCfQl3WjgMo8efqK7w82qvcQA9TcZztAujwXrJFTJDaW7lGHYKHvQdLRxEJQIcF4NE= X-Received: from dlbbu28.prod.google.com ([2002:a05:7022:221c:b0:11d:cdd1:432c]) (user=yubinz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:791:b0:11d:fcc9:f225 with SMTP id a92af1059eb24-11f2ee840f0mr80137c88.14.1765409377793; Wed, 10 Dec 2025 15:29:37 -0800 (PST) Date: Wed, 10 Dec 2025 23:29:13 +0000 In-Reply-To: <20251210-aspeed-sgpio-v3-0-eb8b0cf3dd51@google.com> Mime-Version: 1.0 References: <20251210-aspeed-sgpio-v3-0-eb8b0cf3dd51@google.com> X-Mailer: b4 0.14.2 Message-ID: <20251210-aspeed-sgpio-v3-2-eb8b0cf3dd51@google.com> Subject: [PATCH v3 2/6] hw/gpio/aspeed_sgpio: Add QOM property accessors for SGPIO pins From: Yubin Zou To: qemu-devel@nongnu.org Cc: "=?utf-8?q?C=C3=A9dric_Le_Goater?=" , Peter Maydell , Steven Lee , Troy Lee , Jamin Lin , Andrew Jeffery , Joel Stanley , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , Kane-Chen-AS , Nabih Estefan , qemu-arm@nongnu.org, Yubin Zou Content-Type: text/plain; charset="utf-8" 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::124a; envelope-from=3YQI6aQYKCp4WS9GLXEMMEJC.AMKOCKS-BCTCJLMLELS.MPE@flex--yubinz.bounces.google.com; helo=mail-dl1-x124a.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 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 @google.com) X-ZM-MESSAGEID: 1765409423299158500 Content-Transfer-Encoding: quoted-printable The `aspeed_sgpio_get_pin` and `aspeed_sgpio_set_pin` functions are implemented to get and set the level of individual SGPIO pins. These are then exposed as boolean properties on the SGPIO device object. Signed-off-by: Yubin Zou --- hw/gpio/aspeed_sgpio.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 78 insertions(+) diff --git a/hw/gpio/aspeed_sgpio.c b/hw/gpio/aspeed_sgpio.c index 8676fa7ced134f1f62dc9e30b42c5fe6db3de268..27c406d5042f423b914d53de000= b727cb7242dc9 100644 --- a/hw/gpio/aspeed_sgpio.c +++ b/hw/gpio/aspeed_sgpio.c @@ -91,6 +91,73 @@ static void aspeed_sgpio_2700_write(void *opaque, hwaddr= offset, uint64_t data, } } =20 +static bool aspeed_sgpio_get_pin_level(AspeedSGPIOState *s, int pin) +{ + uint32_t value =3D s->ctrl_regs[pin >> 1]; + bool is_input =3D !(pin % 2); + uint32_t bit_mask =3D 0; + + if (is_input) { + bit_mask =3D SGPIO_SERIAL_IN_VAL_MASK; + } else { + bit_mask =3D SGPIO_SERIAL_OUT_VAL_MASK; + } + + return value & bit_mask; +} + +static void aspeed_sgpio_set_pin_level(AspeedSGPIOState *s, int pin, bool = level) +{ + uint32_t value =3D s->ctrl_regs[pin >> 1]; + bool is_input =3D !(pin % 2); + uint32_t bit_mask =3D 0; + + if (is_input) { + bit_mask =3D SGPIO_SERIAL_IN_VAL_MASK; + } else { + bit_mask =3D SGPIO_SERIAL_OUT_VAL_MASK; + } + + if (level) { + value |=3D bit_mask; + } else { + value &=3D ~bit_mask; + } + s->ctrl_regs[pin >> 1] =3D value; +} + +static void aspeed_sgpio_get_pin(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + bool level =3D true; + int pin =3D 0xfff; + AspeedSGPIOState *s =3D ASPEED_SGPIO(obj); + + if (sscanf(name, "sgpio%03d", &pin) !=3D 1) { + error_setg(errp, "%s: error reading %s", __func__, name); + return; + } + level =3D aspeed_sgpio_get_pin_level(s, pin); + visit_type_bool(v, name, &level, errp); +} + +static void aspeed_sgpio_set_pin(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + bool level; + int pin =3D 0xfff; + AspeedSGPIOState *s =3D ASPEED_SGPIO(obj); + + if (!visit_type_bool(v, name, &level, errp)) { + return; + } + if (sscanf(name, "sgpio%03d", &pin) !=3D 1) { + error_setg(errp, "%s: error reading %s", __func__, name); + return; + } + aspeed_sgpio_set_pin_level(s, pin, level); +} + static const MemoryRegionOps aspeed_gpio_2700_ops =3D { .read =3D aspeed_sgpio_2700_read, .write =3D aspeed_sgpio_2700_write, @@ -114,6 +181,16 @@ static void aspeed_sgpio_realize(DeviceState *dev, Err= or **errp) sysbus_init_mmio(sbd, &s->iomem); } =20 +static void aspeed_sgpio_init(Object *obj) +{ + for (int i =3D 0; i < ASPEED_SGPIO_MAX_PIN_PAIR * 2; i++) { + char *name =3D g_strdup_printf("sgpio%03d", i); + object_property_add(obj, name, "bool", aspeed_sgpio_get_pin, + aspeed_sgpio_set_pin, NULL, NULL); + g_autofree(name); + } +} + static void aspeed_sgpio_class_init(ObjectClass *klass, const void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -143,6 +220,7 @@ static const TypeInfo aspeed_sgpio_ast2700_info =3D { .name =3D TYPE_ASPEED_SGPIO "-ast2700", .parent =3D TYPE_ASPEED_SGPIO, .class_init =3D aspeed_sgpio_2700_class_init, + .instance_init =3D aspeed_sgpio_init, }; =20 static void aspeed_sgpio_register_types(void) --=20 2.52.0.239.gd5f0c6e74e-goog From nobody Wed Dec 17 03:45:25 2025 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=1765409470; cv=none; d=zohomail.com; s=zohoarc; b=XcK9vta0ReO7A0MbugMdnY9zh9TTb/daMR4d6qyRdBrn3bYwTq7yo72/U6hSwEOuGBw+5wBA16slBlyq47Kh+Jx4WbEqDr9kv4ZifK+So0INqVjIAhx0bsrFkHJQ1Rrd3LhIzA1R2o7Kho0cR9YWnd4GvWlTE0B0L/DEOKGwwgc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765409470; 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=DbiJPK3isi4TO87MGtYFXPVGrO1aU7/+qi1vRbNMJMY=; b=hIljHZ7UXTE5gvMgILz3pnuWGg/I3PZGMqmFPHHqLG6Ypih0FTmk8mUqB7ugFUR3hMy5fUs/O3inSXzDx81WeT0GApRxXU6FAU6SebJusDpvpeCdPrvef8TFKQTgM7Fuq0xU0u9F5R7m6oubQRHHaG2i0xfGi99GfRiQwCzDS3E= 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 1765409470708116.41513278681498; Wed, 10 Dec 2025 15:31:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTTcw-000485-7j; Wed, 10 Dec 2025 18:29:46 -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 <3YwI6aQYKCqAYUBINZGOOGLE.COMQEMU-DEVELNONGNU.ORG@flex--yubinz.bounces.google.com>) id 1vTTct-00047f-8A for qemu-devel@nongnu.org; Wed, 10 Dec 2025 18:29:43 -0500 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3YwI6aQYKCqAYUBINZGOOGLE.COMQEMU-DEVELNONGNU.ORG@flex--yubinz.bounces.google.com>) id 1vTTcr-0005hv-HC for qemu-devel@nongnu.org; Wed, 10 Dec 2025 18:29:43 -0500 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-b99d6bd6cc9so661071a12.1 for ; Wed, 10 Dec 2025 15:29:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765409380; x=1766014180; 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=DbiJPK3isi4TO87MGtYFXPVGrO1aU7/+qi1vRbNMJMY=; b=AI3ikaLc0zaj+wiYOQ4TPmJSCKLubvjq0nPIn1B8T4NcOOlebZbL3xkYNk5rayHVXu t4FzoJGw2wTpVTquMjEAnikPZLVfjPA4X19NNju2Ag4JBPLv8WwSJQSTJVVCUZunLxzT rRCsfxiA1FipDz51Pd7+gHW2zE90TmDMNKodmooEd5d9AjZgeSgxkCwEe/VybmvTfYB/ 3c5dQSKf0NZlaGtgVcg0kLuM1jBSiF53BlzrFcdrmLHA2bz8+2UVGcvm3xKlqFIDDypc Z+SjtABg0gv9wH+8BrE5leQoOdkQT1iWgfT69QuxyZyBDaKAMOh1yOikkptkFLnqVq5y E4UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765409380; x=1766014180; 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=DbiJPK3isi4TO87MGtYFXPVGrO1aU7/+qi1vRbNMJMY=; b=dW50goXEvrBI+T/cUqfIuCubUlE8vaOkrxdfrs2JTovP223M5vHj2RPq1dBiffq2GV 6eMS5eFgH4nlLU07JOlo3GnW2WPG1b5duBPQnDOSIyZJqfV8EkKoTRzn3XN79Pr9vR+T J3PR7moLTNDFcL7yW12D0kKOAaaJ0nI/+lyyzOqM4XqzF3kpCAjmuK7Mwelm2y63ioWM p1fqfEdt5rvTH2T3EA8TTVV1CfUC60yiIR0PJJutAWIbEFWzLNmr8qDMklGNTJ5RDP+Q 4Fu0Fwl/SZyIoYzWPmZP1Ypq/Mmdg6v6k6LwiGFTT8IuVlm/JodYKJkfdL7p6Yr2ATtF 2rrA== X-Gm-Message-State: AOJu0YzEX7E4FIH+7AtTkv3wb5AtatTp96D2YgYzXmxRnlcS7EXNid3g H1VGqJ5e4jKAsNgRizGwK7LQg2ELmbtAz5EoBvAygRwKJ4nvjDBQSQxb/t5UQLDk+cvrRi8CZiv 6sUCklez6W81yDgbFtKL8SR2l6p7rYDaW3hjJ64bQXCA9W2ZqhHKUx+PXegADTx4rE0Q9SuL2C7 wy5bsqdXTqeyQiSaO+JQmZqudJKRuPVjYIwkg= X-Google-Smtp-Source: AGHT+IF/kU1Um7JytCYfQKKgIb9G+2cmH9EqURO62c94uClLHcIsqmzTXCDx3W6vx77MvJ594uvUbTlafgg= X-Received: from dynm28.prod.google.com ([2002:a05:7300:2a9c:b0:2a4:6899:e5f0]) (user=yubinz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:2301:b0:2a4:3594:d535 with SMTP id 5a478bee46e88-2ac0544abfbmr4041411eec.2.1765409379492; Wed, 10 Dec 2025 15:29:39 -0800 (PST) Date: Wed, 10 Dec 2025 23:29:14 +0000 In-Reply-To: <20251210-aspeed-sgpio-v3-0-eb8b0cf3dd51@google.com> Mime-Version: 1.0 References: <20251210-aspeed-sgpio-v3-0-eb8b0cf3dd51@google.com> X-Mailer: b4 0.14.2 Message-ID: <20251210-aspeed-sgpio-v3-3-eb8b0cf3dd51@google.com> Subject: [PATCH v3 3/6] hw/gpio/aspeed_sgpio: Implement SGPIO interrupt handling From: Yubin Zou To: qemu-devel@nongnu.org Cc: "=?utf-8?q?C=C3=A9dric_Le_Goater?=" , Peter Maydell , Steven Lee , Troy Lee , Jamin Lin , Andrew Jeffery , Joel Stanley , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , Kane-Chen-AS , Nabih Estefan , qemu-arm@nongnu.org, Yubin Zou Content-Type: text/plain; charset="utf-8" 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::549; envelope-from=3YwI6aQYKCqAYUBINZGOOGLE.COMQEMU-DEVELNONGNU.ORG@flex--yubinz.bounces.google.com; helo=mail-pg1-x549.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: 1765409472771158500 Content-Transfer-Encoding: quoted-printable The SGPIO controller can generate interrupts based on various pin state changes, such as rising/falling edges or high/low levels. This change adds the necessary logic to detect these events, update the interrupt status registers, and signal the interrupt to the SoC. Signed-off-by: Yubin Zou --- include/hw/gpio/aspeed_sgpio.h | 2 + hw/gpio/aspeed_sgpio.c | 126 +++++++++++++++++++++++++++++++++++++= ++-- 2 files changed, 123 insertions(+), 5 deletions(-) diff --git a/include/hw/gpio/aspeed_sgpio.h b/include/hw/gpio/aspeed_sgpio.h index ffdc54a112da8962a7bc5773d524f1d86eb85d39..5dddab80848937417b5f99f1b52= b44f62893bda9 100644 --- a/include/hw/gpio/aspeed_sgpio.h +++ b/include/hw/gpio/aspeed_sgpio.h @@ -58,7 +58,9 @@ struct AspeedSGPIOState { =20 /*< public >*/ MemoryRegion iomem; + int pending; qemu_irq irq; + qemu_irq sgpios[ASPEED_SGPIO_MAX_PIN_PAIR]; uint32_t ctrl_regs[ASPEED_SGPIO_MAX_PIN_PAIR]; uint32_t int_regs[ASPEED_SGPIO_MAX_INT]; }; diff --git a/hw/gpio/aspeed_sgpio.c b/hw/gpio/aspeed_sgpio.c index 27c406d5042f423b914d53de000b727cb7242dc9..4b7797d46acac175249f8a8caf2= daab27c384e9b 100644 --- a/hw/gpio/aspeed_sgpio.c +++ b/hw/gpio/aspeed_sgpio.c @@ -12,15 +12,131 @@ #include "qemu/error-report.h" #include "qapi/error.h" #include "qapi/visitor.h" +#include "hw/irq.h" #include "hw/qdev-properties.h" #include "hw/gpio/aspeed_sgpio.h" =20 +/* + * For each set of gpios there are three sensitivity registers that contr= ol + * the interrupt trigger mode. + * + * | 2 | 1 | 0 | trigger mode + * ----------------------------- + * | 0 | 0 | 0 | falling-edge + * | 0 | 0 | 1 | rising-edge + * | 0 | 1 | 0 | level-low + * | 0 | 1 | 1 | level-high + * | 1 | X | X | dual-edge + */ + +/* GPIO Interrupt Triggers */ +#define ASPEED_FALLING_EDGE 0 +#define ASPEED_RISING_EDGE 1 +#define ASPEED_LEVEL_LOW 2 +#define ASPEED_LEVEL_HIGH 3 +#define ASPEED_DUAL_EDGE 4 + +static void aspeed_clear_irq(AspeedSGPIOState *s, int idx) +{ + uint32_t reg_index =3D idx / 32; + uint32_t bit_index =3D idx % 32; + uint32_t pending =3D extract32(s->int_regs[reg_index], bit_index, 1); + + assert(s->pending >=3D pending); + + /* No change to s->pending if pending is 0 */ + s->pending -=3D pending; + + /* + * The write acknowledged the interrupt regardless of whether it + * was pending or not. The post-condition is that it mustn't be + * pending. Unconditionally clear the status bit. + */ + s->int_regs[reg_index] =3D deposit32(s->int_regs[reg_index], bit_index= , 1, 0); +} + +static void aspeed_evaluate_irq(AspeedSGPIOState *s, int sgpio_prev_high, + int sgpio_curr_high, int idx) +{ + uint32_t ctrl =3D s->ctrl_regs[idx]; + uint32_t falling_edge =3D 0, rising_edge =3D 0; + uint32_t int_trigger =3D SHARED_FIELD_EX32(ctrl, SGPIO_INT_TYPE); + uint32_t int_enabled =3D SHARED_FIELD_EX32(ctrl, SGPIO_INT_EN); + uint32_t reg_index =3D idx / 32; + uint32_t bit_index =3D idx % 32; + + if (!int_enabled) { + return; + } + + /* Detect edges */ + if (sgpio_curr_high && !sgpio_prev_high) { + rising_edge =3D 1; + } else if (!sgpio_curr_high && sgpio_prev_high) { + falling_edge =3D 1; + } + + if (((int_trigger =3D=3D ASPEED_FALLING_EDGE) && falling_edge) || + ((int_trigger =3D=3D ASPEED_RISING_EDGE) && rising_edge) || + ((int_trigger =3D=3D ASPEED_LEVEL_LOW) && !sgpio_curr_high) || + ((int_trigger =3D=3D ASPEED_LEVEL_HIGH) && sgpio_curr_high) || + ((int_trigger >=3D ASPEED_DUAL_EDGE) && (rising_edge || falling_e= dge))) + { + s->int_regs[reg_index] =3D deposit32(s->int_regs[reg_index], + bit_index, 1, 1); + /* Trigger the VIC IRQ */ + s->pending++; + } +} + +static void aspeed_sgpio_update(AspeedSGPIOState *s, uint32_t idx, + uint32_t value) +{ + uint32_t old =3D s->ctrl_regs[idx]; + uint32_t new =3D value; + uint32_t diff =3D (old ^ new); + if (diff) { + /* If the interrupt clear bit is set */ + if (SHARED_FIELD_EX32(new, SGPIO_INT_STATUS)) { + aspeed_clear_irq(s, idx); + /* Clear the interrupt clear bit */ + new &=3D ~SGPIO_INT_STATUS_MASK; + } + + /* Uppdate the control register. */ + s->ctrl_regs[idx] =3D new; + + /* If the output value is changed */ + if (SHARED_FIELD_EX32(diff, SGPIO_SERIAL_OUT_VAL)) { + /* ...trigger the line-state IRQ */ + qemu_set_irq(s->sgpios[idx], 1); + } + + /* If the input value is changed */ + if (SHARED_FIELD_EX32(diff, SGPIO_SERIAL_IN_VAL)) { + aspeed_evaluate_irq(s, + SHARED_FIELD_EX32(old, SGPIO_SERIAL_IN_VAL), + SHARED_FIELD_EX32(new, SGPIO_SERIAL_IN_VAL), + idx); + } + } + qemu_set_irq(s->irq, !!(s->pending)); +} + static uint64_t aspeed_sgpio_2700_read_int_status_reg(AspeedSGPIOState *s, - uint32_t reg) + uint32_t reg) { - return 0; + uint32_t idx =3D reg - R_SGPIO_INT_STATUS_0; + if (idx >=3D ASPEED_SGPIO_MAX_INT) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: interrupt status index: %d, out of bounds\n", + __func__, idx); + return 0; + } + return s->int_regs[idx]; } =20 + static uint64_t aspeed_sgpio_2700_read_control_reg(AspeedSGPIOState *s, uint32_t reg) { @@ -44,7 +160,7 @@ static void aspeed_sgpio_2700_write_control_reg(AspeedSG= PIOState *s, __func__, idx); return; } - s->ctrl_regs[idx] =3D data; + aspeed_sgpio_update(s, idx, data); } =20 static uint64_t aspeed_sgpio_2700_read(void *opaque, hwaddr offset, @@ -58,7 +174,7 @@ static uint64_t aspeed_sgpio_2700_read(void *opaque, hwa= ddr offset, =20 switch (reg) { case R_SGPIO_INT_STATUS_0 ... R_SGPIO_INT_STATUS_7: - aspeed_sgpio_2700_read_int_status_reg(s, reg); + value =3D aspeed_sgpio_2700_read_int_status_reg(s, reg); break; case R_SGPIO_0_CONTROL ... R_SGPIO_255_CONTROL: value =3D aspeed_sgpio_2700_read_control_reg(s, reg); @@ -123,7 +239,7 @@ static void aspeed_sgpio_set_pin_level(AspeedSGPIOState= *s, int pin, bool level) } else { value &=3D ~bit_mask; } - s->ctrl_regs[pin >> 1] =3D value; + aspeed_sgpio_update(s, pin >> 1, value); } =20 static void aspeed_sgpio_get_pin(Object *obj, Visitor *v, const char *name, --=20 2.52.0.239.gd5f0c6e74e-goog From nobody Wed Dec 17 03:45:25 2025 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=1765409487; cv=none; d=zohomail.com; s=zohoarc; b=gQ/fh40JSwXv8GC8UAYKrbHguvBXcbCduhVEwUy/vwiyZU/CY+pQihh8WouUKcbDzZCsEs+oFqQcJo8ZHl3IH3kojEKEIj5UW255vDrV39Lj5a2x0S8o740/KxnsbudJHOaR5MsYn2P5steqVH/3JjmrjwtP7mdBYEs8yOITqUg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765409487; 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=rHDieZbLHiYnj98/qORFPZurA2OWE7iBD9cPzEH+Dlw=; b=duES+6UD+A7bqhCYsrEzCVdx4629ihtXOaheG1KZl8X9W1+a9fmli1Yi4pDR0zv0WmvGgaaIb503lds3e3Jb0bu7+9cFb5DBF2FOeE6eJX7crS+Nmepr7mzHxvP8IlFduwZZIDJ+8A4PY0bcKMX38ONCR0dbILSJPPb++hJLiP0= 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 1765409487873265.73811923911353; Wed, 10 Dec 2025 15:31:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTTcy-00049Q-OW; Wed, 10 Dec 2025 18:29:50 -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 <3ZAI6aQYKCqEZVCJOaHPPHMF.DPNRFNV-EFWFMOPOHOV.PSH@flex--yubinz.bounces.google.com>) id 1vTTcw-00048E-E4 for qemu-devel@nongnu.org; Wed, 10 Dec 2025 18:29:46 -0500 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3ZAI6aQYKCqEZVCJOaHPPHMF.DPNRFNV-EFWFMOPOHOV.PSH@flex--yubinz.bounces.google.com>) id 1vTTct-0005ie-SC for qemu-devel@nongnu.org; Wed, 10 Dec 2025 18:29:45 -0500 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-c0bead25feeso294560a12.0 for ; Wed, 10 Dec 2025 15:29:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765409381; x=1766014181; 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=rHDieZbLHiYnj98/qORFPZurA2OWE7iBD9cPzEH+Dlw=; b=qW0eUJ/9U2Cng7fshZzExROpVD+VWyS0+i6ZA1S8QgDuWfOZ253UYS2Fn3xUQsa/Al YbYA/7rZU3p1CvVPIKopadHkqHYwp9kO+f2tS3w3DfA0Y5krahdc0VNcCEhjU4zh7+tg eHQTg2Gp3om2LQg05tack3HYlbZMYyNXhDge6M2ENiGrW9Aj1bOxHgKOjDJ9fCCS/Yax prZL9E6ftB0saXyd8lEGyC6KL5RNkrDrOXjd+dDEkQmCJckisHa/ZvXoQWeIMpQsJRJ+ e7EUSazN+i2zTbMYIbEuxFYJA/BXgZtcpN0q1y8o8xwfX85KTc/bDO7wZxDhrUjHE3fL Y2LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765409381; x=1766014181; 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=rHDieZbLHiYnj98/qORFPZurA2OWE7iBD9cPzEH+Dlw=; b=oJS9SAlSQ1m5JRTSdJICLxwcDii0/Otzzr5197SAuFiBVW0SwS8L0+38NBq806IcEG 6wglUr07rts053iGacyh3Lh6qvoaE6S4rshSY1r4n43uuJ/ueCW6iTaz3g3nmj8sgF9A 2sW41WtS3G8ulOWqGi1UMj6DYwcrZQtzTD8jP6y3ASNVqjV9kC+yK0ffvWVGsjA+WMY1 AmZCvS8Xp+7Szx2GadEccEgYCU6rf7vbq8VuLG24zLG6rTWBMpD9c0gEFLWGZQvx8BwC QXPVdHUSGW6X1Ld4FAD/zewAeHqU76q72BHCWzEcpFr25420S865hqDhkY4xyycBTw8U 5UnQ== X-Gm-Message-State: AOJu0Yyw28FmZHFHq0EO8OPSCAbjexxgMWEB2ImOpamtPPdiCYb6i1kx ccX/074BM55GdxOMyMmAR0N6HWAuvj5depA5y0TUe4OfHF3DoL+iQ5s0JXn6UDf/O4sqYJ5bHz5 SvjQmj+BqCdZQ0UooKeQK7qljfNJZv4IJVCad+F+vyD+zj2HzUtINlNPNATA/YdbhSF4vPQIUCK S29sU+BEnjD0d2Z1lvi9XINbCSUsCr8G+RTlA= X-Google-Smtp-Source: AGHT+IEL/IhlkELZonhzWn2r5xauTVadk1P/NM39jdyUjVUzYRXP0WE0ZVT9aDwGbQW9DU0mSpyy+Cyme94= X-Received: from dlbcq18.prod.google.com ([2002:a05:7022:2492:b0:11d:cf4c:62ab]) (user=yubinz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:78f:b0:119:e55a:9c06 with SMTP id a92af1059eb24-11f296d74cbmr3308649c88.34.1765409380954; Wed, 10 Dec 2025 15:29:40 -0800 (PST) Date: Wed, 10 Dec 2025 23:29:15 +0000 In-Reply-To: <20251210-aspeed-sgpio-v3-0-eb8b0cf3dd51@google.com> Mime-Version: 1.0 References: <20251210-aspeed-sgpio-v3-0-eb8b0cf3dd51@google.com> X-Mailer: b4 0.14.2 Message-ID: <20251210-aspeed-sgpio-v3-4-eb8b0cf3dd51@google.com> Subject: [PATCH v3 4/6] hw/arm/aspeed_soc: Update Aspeed SoC to support two SGPIO controllers From: Yubin Zou To: qemu-devel@nongnu.org Cc: "=?utf-8?q?C=C3=A9dric_Le_Goater?=" , Peter Maydell , Steven Lee , Troy Lee , Jamin Lin , Andrew Jeffery , Joel Stanley , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , Kane-Chen-AS , Nabih Estefan , qemu-arm@nongnu.org, Yubin Zou Content-Type: text/plain; charset="utf-8" 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::54a; envelope-from=3ZAI6aQYKCqEZVCJOaHPPHMF.DPNRFNV-EFWFMOPOHOV.PSH@flex--yubinz.bounces.google.com; helo=mail-pg1-x54a.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: 1765409488851158500 Content-Transfer-Encoding: quoted-printable This commit updates the Aspeed SoC model to support two SGPIO controllers, reflecting the hardware capabilities of the AST2700 The memory map and interrupt map are updated to include entries for two SGPIO controllers (SGPIOM0 and SGPIOM1). This change is a prerequisite for the full implementation of the SGPIO device model. Signed-off-by: Yubin Zou --- include/hw/arm/aspeed_soc.h | 8 ++++++-- hw/arm/aspeed_ast10x0.c | 6 +++--- hw/arm/aspeed_ast27x0.c | 10 ++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h index 4b8e599f1a53bfb2e4d3196d5495cd316f799354..18ff961a38508c5df83b46e187f= 732d736443f20 100644 --- a/include/hw/arm/aspeed_soc.h +++ b/include/hw/arm/aspeed_soc.h @@ -32,6 +32,7 @@ #include "hw/net/ftgmac100.h" #include "target/arm/cpu.h" #include "hw/gpio/aspeed_gpio.h" +#include "hw/gpio/aspeed_sgpio.h" #include "hw/sd/aspeed_sdhci.h" #include "hw/usb/hcd-ehci.h" #include "qom/object.h" @@ -46,6 +47,7 @@ #define VBOOTROM_FILE_NAME "ast27x0_bootrom.bin" =20 #define ASPEED_SPIS_NUM 3 +#define ASPEED_SGPIO_NUM 2 #define ASPEED_EHCIS_NUM 4 #define ASPEED_WDTS_NUM 8 #define ASPEED_CPUS_NUM 4 @@ -89,6 +91,7 @@ struct AspeedSoCState { AspeedMiiState mii[ASPEED_MACS_NUM]; AspeedGPIOState gpio; AspeedGPIOState gpio_1_8v; + AspeedSGPIOState sgpiom[ASPEED_SGPIO_NUM]; AspeedSDHCIState sdhci; AspeedSDHCIState emmc; AspeedLPCState lpc; @@ -106,7 +109,6 @@ struct AspeedSoCState { UnimplementedDeviceState pwm; UnimplementedDeviceState espi; UnimplementedDeviceState udc; - UnimplementedDeviceState sgpiom; UnimplementedDeviceState ltpi; UnimplementedDeviceState jtag[ASPEED_JTAG_NUM]; AspeedAPB2OPBState fsi[2]; @@ -166,6 +168,7 @@ struct AspeedSoCClass { uint64_t secsram_size; int pcie_num; int spis_num; + int sgpio_num; int ehcis_num; int wdts_num; int macs_num; @@ -221,6 +224,8 @@ enum { ASPEED_DEV_SDHCI, ASPEED_DEV_GPIO, ASPEED_DEV_GPIO_1_8V, + ASPEED_DEV_SGPIOM0, + ASPEED_DEV_SGPIOM1, ASPEED_DEV_RTC, ASPEED_DEV_TIMER1, ASPEED_DEV_TIMER2, @@ -263,7 +268,6 @@ enum { ASPEED_DEV_I3C, ASPEED_DEV_ESPI, ASPEED_DEV_UDC, - ASPEED_DEV_SGPIOM, ASPEED_DEV_JTAG0, ASPEED_DEV_JTAG1, ASPEED_DEV_FSI1, diff --git a/hw/arm/aspeed_ast10x0.c b/hw/arm/aspeed_ast10x0.c index 7f49c13391be0b923e317409a0fccfa741f5e658..c141cc080422579ca6b6965369d= 84dfbe416247b 100644 --- a/hw/arm/aspeed_ast10x0.c +++ b/hw/arm/aspeed_ast10x0.c @@ -36,7 +36,7 @@ static const hwaddr aspeed_soc_ast1030_memmap[] =3D { [ASPEED_DEV_ESPI] =3D 0x7E6EE000, [ASPEED_DEV_SBC] =3D 0x7E6F2000, [ASPEED_DEV_GPIO] =3D 0x7E780000, - [ASPEED_DEV_SGPIOM] =3D 0x7E780500, + [ASPEED_DEV_SGPIOM0] =3D 0x7E780500, [ASPEED_DEV_TIMER1] =3D 0x7E782000, [ASPEED_DEV_UART1] =3D 0x7E783000, [ASPEED_DEV_UART2] =3D 0x7E78D000, @@ -94,7 +94,7 @@ static const int aspeed_soc_ast1030_irqmap[] =3D { [ASPEED_DEV_I2C] =3D 110, /* 110 ~ 123 */ [ASPEED_DEV_KCS] =3D 138, /* 138 -> 142 */ [ASPEED_DEV_UDC] =3D 9, - [ASPEED_DEV_SGPIOM] =3D 51, + [ASPEED_DEV_SGPIOM0] =3D 51, [ASPEED_DEV_JTAG0] =3D 27, [ASPEED_DEV_JTAG1] =3D 53, }; @@ -427,7 +427,7 @@ static void aspeed_soc_ast1030_realize(DeviceState *dev= _soc, Error **errp) sc->memmap[ASPEED_DEV_UDC], 0x1000); aspeed_mmio_map_unimplemented(s->memory, SYS_BUS_DEVICE(&s->sgpiom), "aspeed.sgpiom", - sc->memmap[ASPEED_DEV_SGPIOM], 0x100); + sc->memmap[ASPEED_DEV_SGPIOM0], 0x100); =20 aspeed_mmio_map_unimplemented(s->memory, SYS_BUS_DEVICE(&s->jtag[0]), "aspeed.jtag", diff --git a/hw/arm/aspeed_ast27x0.c b/hw/arm/aspeed_ast27x0.c index c484bcd4e22fb49faf9c16992ae2cdfd6cd82da4..e5f04bd16e80696e41005d9062a= 6df6d060b8088 100644 --- a/hw/arm/aspeed_ast27x0.c +++ b/hw/arm/aspeed_ast27x0.c @@ -69,6 +69,8 @@ static const hwaddr aspeed_soc_ast2700_memmap[] =3D { [ASPEED_DEV_ADC] =3D 0x14C00000, [ASPEED_DEV_SCUIO] =3D 0x14C02000, [ASPEED_DEV_GPIO] =3D 0x14C0B000, + [ASPEED_DEV_SGPIOM0] =3D 0x14C0C000, + [ASPEED_DEV_SGPIOM1] =3D 0x14C0D000, [ASPEED_DEV_I2C] =3D 0x14C0F000, [ASPEED_DEV_INTCIO] =3D 0x14C18000, [ASPEED_DEV_PCIE_PHY2] =3D 0x14C1C000, @@ -122,6 +124,8 @@ static const int aspeed_soc_ast2700a0_irqmap[] =3D { [ASPEED_DEV_KCS] =3D 128, [ASPEED_DEV_ADC] =3D 130, [ASPEED_DEV_GPIO] =3D 130, + [ASPEED_DEV_SGPIOM0] =3D 130, + [ASPEED_DEV_SGPIOM1] =3D 130, [ASPEED_DEV_I2C] =3D 130, [ASPEED_DEV_FMC] =3D 131, [ASPEED_DEV_WDT] =3D 131, @@ -173,6 +177,8 @@ static const int aspeed_soc_ast2700a1_irqmap[] =3D { [ASPEED_DEV_I2C] =3D 194, [ASPEED_DEV_ADC] =3D 194, [ASPEED_DEV_GPIO] =3D 194, + [ASPEED_DEV_SGPIOM0] =3D 194, + [ASPEED_DEV_SGPIOM1] =3D 194, [ASPEED_DEV_FMC] =3D 195, [ASPEED_DEV_WDT] =3D 195, [ASPEED_DEV_PWM] =3D 195, @@ -214,6 +220,8 @@ static const int ast2700_gic130_gic194_intcmap[] =3D { [ASPEED_DEV_I2C] =3D 0, [ASPEED_DEV_ADC] =3D 16, [ASPEED_DEV_GPIO] =3D 18, + [ASPEED_DEV_SGPIOM0] =3D 21, + [ASPEED_DEV_SGPIOM1] =3D 24, }; =20 /* GICINT 131 */ @@ -1061,6 +1069,7 @@ static void aspeed_soc_ast2700a0_class_init(ObjectCla= ss *oc, const void *data) sc->sram_size =3D 0x20000; sc->pcie_num =3D 0; sc->spis_num =3D 3; + sc->sgpio_num =3D 2; sc->ehcis_num =3D 2; sc->wdts_num =3D 8; sc->macs_num =3D 1; @@ -1089,6 +1098,7 @@ static void aspeed_soc_ast2700a1_class_init(ObjectCla= ss *oc, const void *data) sc->sram_size =3D 0x20000; sc->pcie_num =3D 3; sc->spis_num =3D 3; + sc->sgpio_num =3D 2; sc->ehcis_num =3D 4; sc->wdts_num =3D 8; sc->macs_num =3D 3; --=20 2.52.0.239.gd5f0c6e74e-goog From nobody Wed Dec 17 03:45:25 2025 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=1765409470; cv=none; d=zohomail.com; s=zohoarc; b=jZIZ9dEAQDhA7HI5uS/jl7kLmn9o30eUc4Zq8bolJwijNTG+2bQi/ZsWHk5e2xIWLv638ckb4uEPAmprN3Uefjps2jg9L2HN9AAYGM/YNBFLAuJF+dCosojPNji/jWzC7N/2jD0iRlLN/xtxb6t3Zs38bAK0YoVHdosinnCEXz8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765409470; 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=hqZ2qhWGGDuvHlPFLsB8stzNSOZI8NxOWfwLsS50KE0=; b=XeergdfvYi1Lwvxe4MKbsRb2i1kOp2k5OI6YzlTbn/MhiN9D5vx1fGbsQkpJElgIjTXWC+3IcxMLYZ0yguW9vL6G9OdTjg6yHQt7tT24BwRqCyHnHhGwGUYfj57miPEAgFGu8/SG2rzDJYv1fyBvuIzBMUhp/Xs0Jq1rVTzFCQg= 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 1765409470655881.468868333726; Wed, 10 Dec 2025 15:31:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTTd8-0004DH-5s; Wed, 10 Dec 2025 18:29:58 -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 <3ZgI6aQYKCqMbXELQcJRRJOH.FRPTHPX-GHYHOQRQJQX.RUJ@flex--yubinz.bounces.google.com>) id 1vTTcy-00049P-MU for qemu-devel@nongnu.org; Wed, 10 Dec 2025 18:29:48 -0500 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3ZgI6aQYKCqMbXELQcJRRJOH.FRPTHPX-GHYHOQRQJQX.RUJ@flex--yubinz.bounces.google.com>) id 1vTTcu-0005j4-FT for qemu-devel@nongnu.org; Wed, 10 Dec 2025 18:29:47 -0500 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-bc240cdb249so317897a12.3 for ; Wed, 10 Dec 2025 15:29:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765409383; x=1766014183; 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=hqZ2qhWGGDuvHlPFLsB8stzNSOZI8NxOWfwLsS50KE0=; b=RgPMNeWrdZtbnAztSu7g/QjCqyGRA3A4mA7+hHtWDVPESaXuFyCgkth1E94O73tWvJ duSXeeqnCxuiPpS3HOK8DMHvvZKLCZt+13j2/aitnLot/E1tb2yBREi2duwiqTXG2c9X NxT2BBmtNRSumZASJOV7mlDxiLhYJcz2IVVwNnJmjs1nGt5zV9P78WRFE1N9gS6Hvdj6 pjszupyJbVqA19to1l/M8Z7uLoMHd09a+rIJyz5+PUPBleYSM64+Ip5+8ggFSYscIyec eA0r967dHBOBZfdx3GWPYrkdUyzO6U2BQil9dRmTLibegST9UcJhJnCvzV9Cyo+QY8dh Bgpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765409383; x=1766014183; 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=hqZ2qhWGGDuvHlPFLsB8stzNSOZI8NxOWfwLsS50KE0=; b=Cd5YiYZwozK+CWseu3D2qkKlr3y7TO39yTuogO8xPSZRkjhox5urvb7H0LocqjstzA TGHZesRoI/bE1zSFXjMTzDH+1/JwVcr0DOGLssbz0JwB+SsyvFG96oFWtRbP9dGh/Xzk ahBbxjFRVbaR1sLcFg7J/puoz1zxTDJZg+C4/q1FPJlyz+PHC3sQdZg4mVmODuKF5DRP EULCtgsKtLdWbG1P086rBBTjjyPlAw+E+l6O8Cu2BbP7RL1lAU2Ngd8ljxEp97cfSva4 qAu4w2yMu6WLOL+C8PH2yEMQ5apNZYKCbIXRfCgXy4sxuqzfJU4Nc0SlgdbArIjvjdYs mYPw== X-Gm-Message-State: AOJu0Yyef3rkTnX7KzgRIi0bSv0HZVwyBtJUOTaoMODAsIVnolPhrdF2 BvHydfb07K1pgy7jIrRTStka2jLeaJ5MJCUFUwSlsjzjVGv6t7C/lBvOv+6k14n1biG2qAgWYOK QBMJYvzkd0BSvk0FWTBGmxbtJPPxjzUZvGdtJ0Ghsds5DvWL2HniXpN6ZgswnJ9n/bNgZkz37DI yIP2cVXGPI/Yc/AJJGqVeVw1uHNmpAatdj9+k= X-Google-Smtp-Source: AGHT+IEn5a/inZouAECTkDQNNeEkn6ggqHKOx/PwjvTPQIlfd0iQs3c1dQXEPiI/UxHzNVgAzeSjxBSYxLo= X-Received: from dlbbu30.prod.google.com ([2002:a05:7022:221e:b0:11d:fd0d:f00f]) (user=yubinz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:fd0b:b0:11b:9386:a386 with SMTP id a92af1059eb24-11f296d7b96mr3265379c88.41.1765409382643; Wed, 10 Dec 2025 15:29:42 -0800 (PST) Date: Wed, 10 Dec 2025 23:29:16 +0000 In-Reply-To: <20251210-aspeed-sgpio-v3-0-eb8b0cf3dd51@google.com> Mime-Version: 1.0 References: <20251210-aspeed-sgpio-v3-0-eb8b0cf3dd51@google.com> X-Mailer: b4 0.14.2 Message-ID: <20251210-aspeed-sgpio-v3-5-eb8b0cf3dd51@google.com> Subject: [PATCH v3 5/6] hw/arm/aspeed_ast27x0: Wire SGPIO controller to AST2700 SoC From: Yubin Zou To: qemu-devel@nongnu.org Cc: "=?utf-8?q?C=C3=A9dric_Le_Goater?=" , Peter Maydell , Steven Lee , Troy Lee , Jamin Lin , Andrew Jeffery , Joel Stanley , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , Kane-Chen-AS , Nabih Estefan , qemu-arm@nongnu.org, Yubin Zou Content-Type: text/plain; charset="utf-8" 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::549; envelope-from=3ZgI6aQYKCqMbXELQcJRRJOH.FRPTHPX-GHYHOQRQJQX.RUJ@flex--yubinz.bounces.google.com; helo=mail-pg1-x549.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: 1765409472733158500 Content-Transfer-Encoding: quoted-printable This commit integrates the Aspeed SGPIO controller into the AST2700 Signed-off-by: Yubin Zou --- hw/arm/aspeed_ast27x0.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hw/arm/aspeed_ast27x0.c b/hw/arm/aspeed_ast27x0.c index e5f04bd16e80696e41005d9062a6df6d060b8088..787accadbecae376d0c747d054e= c6372785375b1 100644 --- a/hw/arm/aspeed_ast27x0.c +++ b/hw/arm/aspeed_ast27x0.c @@ -519,6 +519,11 @@ static void aspeed_soc_ast2700_init(Object *obj) snprintf(typename, sizeof(typename), "aspeed.gpio-%s", socname); object_initialize_child(obj, "gpio", &s->gpio, typename); =20 + snprintf(typename, sizeof(typename), "aspeed.sgpio-%s", socname); + for (i =3D 0; i < sc->sgpio_num; i++) { + object_initialize_child(obj, "sgpio[*]", &s->sgpiom[i], typename); + } + object_initialize_child(obj, "rtc", &s->rtc, TYPE_ASPEED_RTC); =20 snprintf(typename, sizeof(typename), "aspeed.sdhci-%s", socname); @@ -973,6 +978,17 @@ static void aspeed_soc_ast2700_realize(DeviceState *de= v, Error **errp) sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio), 0, aspeed_soc_ast2700_get_irq(s, ASPEED_DEV_GPIO)); =20 + /* SGPIO */ + for (i =3D 0; i < sc->sgpio_num; i++) { + if (!sysbus_realize(SYS_BUS_DEVICE(&s->sgpiom[i]), errp)) { + return; + } + aspeed_mmio_map(s->memory, SYS_BUS_DEVICE(&s->sgpiom[i]), 0, + sc->memmap[ASPEED_DEV_SGPIOM0 + i]); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->sgpiom[i]), 0, + aspeed_soc_ast2700_get_irq(s, ASPEED_DEV_SGPIOM0 += i)); + } + /* RTC */ if (!sysbus_realize(SYS_BUS_DEVICE(&s->rtc), errp)) { return; --=20 2.52.0.239.gd5f0c6e74e-goog From nobody Wed Dec 17 03:45:25 2025 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=1765409434; cv=none; d=zohomail.com; s=zohoarc; b=VHjZ0AfEQr49eorWMLmWJzt+Ec6/CBvHue8JnoauAh5LJVDgdvCzJa/RkTOkWLMYKH76gHAU9DVbxA6+qI24FD2YDb9yUzCw52DB22d5eBPgUzn7VdBfnRxM4aYM6LEVbZq3GQEsFD3k06sdx9+AYgnrgkO1o6g/kO+XUzqmcck= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765409434; 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=V/p7p5kZiMeVzqeCpGXZV3o/BNSDBxLa3oyslXCE1Sk=; b=ZqOiG4IAommmhAf7Lm2KNz7d52C2ZD3sNoePycYvUMBGf/Icw6bf3iIHi1BB3ZTZT6ZLyZ4Dfg+4rw611QTHapaAnZyAnbsiwV+svmqh7UmB2MZdGQubnFAkdoBVLugzy5UlSDHjzuL62Cal8SNVz+zm4v+kbkFl4pxb4ucWghw= 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 1765409434644969.9587622861148; Wed, 10 Dec 2025 15:30:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vTTd7-0004Cv-OU; Wed, 10 Dec 2025 18:29:57 -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 <3aAI6aQYKCqUdZGNSeLTTLQJ.HTRVJRZ-IJaJQSTSLSZ.TWL@flex--yubinz.bounces.google.com>) id 1vTTd0-0004AG-Pz for qemu-devel@nongnu.org; Wed, 10 Dec 2025 18:29:50 -0500 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3aAI6aQYKCqUdZGNSeLTTLQJ.HTRVJRZ-IJaJQSTSLSZ.TWL@flex--yubinz.bounces.google.com>) id 1vTTcy-0005jL-Da for qemu-devel@nongnu.org; Wed, 10 Dec 2025 18:29:49 -0500 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-b471737e673so372613a12.1 for ; Wed, 10 Dec 2025 15:29:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765409384; x=1766014184; 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=V/p7p5kZiMeVzqeCpGXZV3o/BNSDBxLa3oyslXCE1Sk=; b=f9hUcmNvCVDVI4969Bfa6rt1jhb+81inln16CRKyFHJ5NJfh1BBoXvLT8P2vd+Uo1J mTa/oxyeoS7HKxp70iFM3vHb8hggXGywZmsVK2TX65Y3a+jbEjrL/b+YxxWwqow7kknl GV1gPpoWodVH/bmog7KhQpPombRMSfIiZAI8eOdZe8ZEsE0NuCBDskdNWEM6cvedwTUy SYwJ7pqRwM0AZxoGO43eGdv+l3JeaoNeAEgADSEoZQ4q7rRthUO9Ms4lXmtuBDPjI5zL SmpANUjiPZF+pwdKkLnPF5RC7aexADWAwGjOmCSFy/JPBwZlD6ppGEcoJQLmSvo4a3qj r41g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765409384; x=1766014184; 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=V/p7p5kZiMeVzqeCpGXZV3o/BNSDBxLa3oyslXCE1Sk=; b=wcPA9CZBrD5FchKDj7P7AmNYQOjJ4GhGTrNKePa6OjPw4VOgPuYG+RowwkPf9mtirx VxEgTCTAgtF3MhK0VlA6KxNryS/acKqs/pE3SX/ANbOcJUJ9vaelwHD6HUtq2JmMZ7kL T/4lhm3TNqJdgFZWlA2E92tNLz41oKg5ij6hmnTPyPFIphggSOVEukjvBoBk7BI3OBC0 uDiTcLYWvu0pbjgKgxedsLio4sl+nQ+/qnpt7MGC0hj+c5hRT/f4lQOP6U5CU/13R4L6 qGu9hsosq6V+Asv1yGIMFVakW7DDepESwI9e8dGn4uYq3sIL+wHCkoFZ+yXU6vRn0sob QlWg== X-Gm-Message-State: AOJu0YwoMvVnRnrDIhQhuvd0a5PmEeZWMk4S8Y4HWG3ZAY2TUUE02FQY veF7MHjbOD2Cd/eO2mC6oTHwq3PJLv2EqQTlSXkkqClAnf1biwC1bCrUoBD/jR7BulaoU1tbQI5 nmXljMRUyozR9l4KrHXLxk1jcBaNq2a7a/LjNddRi6gkW5xY3T77mQNtJ5vvpgK2psMA/HzvOw5 p79f0phVBtphEba9u24OiLT5xmW4c7/6DZdd8= X-Google-Smtp-Source: AGHT+IFnH1Uj5Zp6ckTavj8XiQlSDJn8c8GXpiFB4Kilp7a2eKpL0MER75YlbhZzBEKq2HvudOppQknKwWg= X-Received: from dlbrb20.prod.google.com ([2002:a05:7022:f014:b0:11b:a892:80ac]) (user=yubinz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:e21:b0:119:e569:f615 with SMTP id a92af1059eb24-11f2963f1bamr3036459c88.14.1765409384218; Wed, 10 Dec 2025 15:29:44 -0800 (PST) Date: Wed, 10 Dec 2025 23:29:17 +0000 In-Reply-To: <20251210-aspeed-sgpio-v3-0-eb8b0cf3dd51@google.com> Mime-Version: 1.0 References: <20251210-aspeed-sgpio-v3-0-eb8b0cf3dd51@google.com> X-Mailer: b4 0.14.2 Message-ID: <20251210-aspeed-sgpio-v3-6-eb8b0cf3dd51@google.com> Subject: [PATCH v3 6/6] test/qtest: Add Unit test for Aspeed SGPIO From: Yubin Zou To: qemu-devel@nongnu.org Cc: "=?utf-8?q?C=C3=A9dric_Le_Goater?=" , Peter Maydell , Steven Lee , Troy Lee , Jamin Lin , Andrew Jeffery , Joel Stanley , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , Kane-Chen-AS , Nabih Estefan , qemu-arm@nongnu.org, Yubin Zou Content-Type: text/plain; charset="utf-8" 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::549; envelope-from=3aAI6aQYKCqUdZGNSeLTTLQJ.HTRVJRZ-IJaJQSTSLSZ.TWL@flex--yubinz.bounces.google.com; helo=mail-pg1-x549.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: 1765409437142158500 Content-Transfer-Encoding: quoted-printable This commit introduces a new qtest for the Aspeed SGPIO controller The test covers the following: - Setting and clearing SGPIO output pins and verifying the pin state. - Setting and clearing SGPIO input pins and verifying the pin state. - Verifying that level-high interrupts are correctly triggered and cleare= d. Signed-off-by: Yubin Zou --- tests/qtest/ast2700-sgpio-test.c | 152 +++++++++++++++++++++++++++++++++++= ++++ tests/qtest/meson.build | 1 + 2 files changed, 153 insertions(+) diff --git a/tests/qtest/ast2700-sgpio-test.c b/tests/qtest/ast2700-sgpio-t= est.c new file mode 100644 index 0000000000000000000000000000000000000000..fc52839c4b149a3010c6a035d8b= 29f9ad295930a --- /dev/null +++ b/tests/qtest/ast2700-sgpio-test.c @@ -0,0 +1,152 @@ +/* + * QTest testcase for the ASPEED AST2700 GPIO Controller. + * + * SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (C) 2025 Google LLC. + */ + +#include "qemu/osdep.h" +#include "qobject/qdict.h" +#include "qemu/bitops.h" +#include "qemu/timer.h" +#include "qobject/qdict.h" +#include "libqtest-single.h" +#include "qemu/error-report.h" +#include "hw/registerfields.h" +#include "hw/gpio/aspeed_sgpio.h" + +#define ASPEED_SGPIO_MAX_PIN_PAIR 256 +#define AST2700_SGPIO0_BASE 0x14C0C000 +#define AST2700_SGPIO1_BASE 0x14C0D000 + +static void test_output_pins(const char *machine, const uint32_t base, int= idx) +{ + QTestState *s =3D qtest_init(machine); + char name[16]; + char qom_path[64]; + uint32_t offset =3D 0; + uint32_t value =3D 0; + for (int i =3D 0; i < ASPEED_SGPIO_MAX_PIN_PAIR; i++) { + /* Odd index is output port */ + sprintf(name, "sgpio%d", i * 2 + 1); + sprintf(qom_path, "/machine/soc/sgpio[%d]", idx); + offset =3D base + (R_SGPIO_0_CONTROL + i) * 4; + /* set serial output */ + qtest_writel(s, offset, 0x00000001); + value =3D qtest_readl(s, offset); + g_assert_cmphex(SHARED_FIELD_EX32(value, SGPIO_SERIAL_OUT_VAL), = =3D=3D, 1); + g_assert_cmphex(qtest_qom_get_bool(s, qom_path, name), =3D=3D, tru= e); + + /* clear serial output */ + qtest_writel(s, offset, 0x00000000); + value =3D qtest_readl(s, offset); + g_assert_cmphex(SHARED_FIELD_EX32(value, SGPIO_SERIAL_OUT_VAL), = =3D=3D, 0); + g_assert_cmphex(qtest_qom_get_bool(s, qom_path, name), =3D=3D, fal= se); + } + qtest_quit(s); +} + +static void test_input_pins(const char *machine, const uint32_t base, int = idx) +{ + QTestState *s =3D qtest_init(machine); + char name[16]; + char qom_path[64]; + uint32_t offset =3D 0; + uint32_t value =3D 0; + for (int i =3D 0; i < ASPEED_SGPIO_MAX_PIN_PAIR; i++) { + /* Even index is input port */ + sprintf(name, "sgpio%d", i * 2); + sprintf(qom_path, "/machine/soc/sgpio[%d]", idx); + offset =3D base + (R_SGPIO_0_CONTROL + i) * 4; + /* set serial input */ + qtest_qom_set_bool(s, qom_path, name, true); + value =3D qtest_readl(s, offset); + g_assert_cmphex(SHARED_FIELD_EX32(value, SGPIO_SERIAL_IN_VAL), =3D= =3D, 1); + g_assert_cmphex(qtest_qom_get_bool(s, qom_path, name), =3D=3D, tru= e); + + /* clear serial input */ + qtest_qom_set_bool(s, qom_path, name, false); + value =3D qtest_readl(s, offset); + g_assert_cmphex(SHARED_FIELD_EX32(value, SGPIO_SERIAL_IN_VAL), =3D= =3D, 0); + g_assert_cmphex(qtest_qom_get_bool(s, qom_path, name), =3D=3D, fal= se); + } + qtest_quit(s); +} + +static void test_irq_level_high(const char *machine, + const uint32_t base, int idx) +{ + QTestState *s =3D qtest_init(machine); + char name[16]; + char qom_path[64]; + uint32_t ctrl_offset =3D 0; + uint32_t int_offset =3D 0; + uint32_t int_reg_idx =3D 0; + uint32_t int_bit_idx =3D 0; + uint32_t value =3D 0; + for (int i =3D 0; i < ASPEED_SGPIO_MAX_PIN_PAIR; i++) { + /* Even index is input port */ + sprintf(name, "sgpio%d", i * 2); + sprintf(qom_path, "/machine/soc/sgpio[%d]", idx); + int_reg_idx =3D i / 32; + int_bit_idx =3D i % 32; + int_offset =3D base + (R_SGPIO_INT_STATUS_0 + int_reg_idx) * 4; + ctrl_offset =3D base + (R_SGPIO_0_CONTROL + i) * 4; + + /* Enable the interrupt */ + value =3D SHARED_FIELD_DP32(value, SGPIO_INT_EN, 1); + qtest_writel(s, ctrl_offset, value); + + /* Set the interrupt type to level-high trigger */ + value =3D SHARED_FIELD_DP32(qtest_readl(s, ctrl_offset), + SGPIO_INT_TYPE, 3); + qtest_writel(s, ctrl_offset, value); + + /* Set serial input high */ + qtest_qom_set_bool(s, qom_path, name, true); + value =3D qtest_readl(s, ctrl_offset); + g_assert_cmphex(SHARED_FIELD_EX32(value, SGPIO_SERIAL_IN_VAL), =3D= =3D, 1); + + /* Interrupt status is set */ + value =3D qtest_readl(s, int_offset); + g_assert_cmphex(extract32(value, int_bit_idx, 1), =3D=3D, 1); + + /* Clear Interrupt */ + value =3D SHARED_FIELD_DP32(qtest_readl(s, ctrl_offset), + SGPIO_INT_STATUS, 1); + qtest_writel(s, ctrl_offset, value); + value =3D qtest_readl(s, int_offset); + g_assert_cmphex(extract32(value, int_bit_idx, 1), =3D=3D, 0); + + /* Clear serial input */ + qtest_qom_set_bool(s, qom_path, name, false); + value =3D qtest_readl(s, ctrl_offset); + g_assert_cmphex(SHARED_FIELD_EX32(value, SGPIO_SERIAL_IN_VAL), =3D= =3D, 0); + } + qtest_quit(s); +} + +static void test_2700_input_pins(void) +{ + test_input_pins("-machine ast2700-evb", + AST2700_SGPIO0_BASE, 0); + test_input_pins("-machine ast2700-evb", + AST2700_SGPIO1_BASE, 1); + test_output_pins("-machine ast2700-evb", + AST2700_SGPIO0_BASE, 0); + test_output_pins("-machine ast2700-evb", + AST2700_SGPIO1_BASE, 1); + test_irq_level_high("-machine ast2700-evb", + AST2700_SGPIO0_BASE, 0); + test_irq_level_high("-machine ast2700-evb", + AST2700_SGPIO1_BASE, 1); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + qtest_add_func("/ast2700/sgpio/input_pins", test_2700_input_pins); + + return g_test_run(); +} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 669d07c06bdedc6be0c69acadeba989dc15ddf3f..5c80b2ed6de1f453d2483db482c= 1b0e7801ba980 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -221,6 +221,7 @@ qtests_aspeed =3D \ qtests_aspeed64 =3D \ ['ast2700-gpio-test', 'ast2700-hace-test', + 'ast2700-sgpio-test', 'ast2700-smc-test'] =20 qtests_stm32l4x5 =3D \ --=20 2.52.0.239.gd5f0c6e74e-goog