From nobody Sun Dec 14 06:42:50 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=1765238566; cv=none; d=zohomail.com; s=zohoarc; b=EDJ09vZIjdgV4gi9oJWfbCBA59t0X+tX4P+hi4BAdGHUEqRGLpJh4lSXZhn0iqT5N6mKnRPtE9SpqJ/LgWN+duRplTCQnhv9VFzChXt316vo/aDAf72Gz4GTttRO3IQ2dlkXLMahZ6AS1jb4CWDETeQ6l3xAmH7zrmeUJFmlTr0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765238566; 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=/4FW5co9+fSyaHV9OmjivazZbsmT2AI4p/mhxSPLytQ=; b=SIYWckfBJEg1P7nj4fcXG68uPjC2Za80vrWp2yYjZfci7oFK6cevpg6sI7q+B58V9bMvVQxBQWYj6S36EYjUSMPDoYrQwlKGba580t21olXWmjh3iwfBKkNXk8UGQXTC8EiRxgfg163Lr+r6745HVnC0ldmcZkBQ/3PUbk66xiM= 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 1765238566233304.60318869276784; Mon, 8 Dec 2025 16:02:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vSlAx-0007BA-9S; Mon, 08 Dec 2025 19:01:56 -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 <36mY3aQYKCuUfbIPUgNVVNSL.JVTXLTb-KLcLSUVUNUb.VYN@flex--yubinz.bounces.google.com>) id 1vSlAt-0007A2-T5 for qemu-devel@nongnu.org; Mon, 08 Dec 2025 19:01:52 -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 <36mY3aQYKCuUfbIPUgNVVNSL.JVTXLTb-KLcLSUVUNUb.VYN@flex--yubinz.bounces.google.com>) id 1vSlAr-0007Rm-Up for qemu-devel@nongnu.org; Mon, 08 Dec 2025 19:01:51 -0500 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-b609c0f6522so8614439a12.3 for ; Mon, 08 Dec 2025 16:01:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765238507; x=1765843307; 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=/4FW5co9+fSyaHV9OmjivazZbsmT2AI4p/mhxSPLytQ=; b=sjUs2wKiswKjnChXLESAnwy9oozhQLYHlO7j/Nha7YzCFjUn2qjGcokkoIC1IxPXCq 5BnoGjdYZTfFHxB6eg2+AMGenTnZi2VvB3jXC06sq9qElYOI4v1h/pbm3gmHKDU1AXjv 1vYQ7YVMgwaFBrunDC0yJD5MqdTlF5FvDuFtp16X15VY9ZnF9Kg9hpyFsgs/5/XDTvj6 L9XpKIZrzoPc6F8MRg2iuOxM+WfyEu7fi4G1gIt7nuDH0RdYNA3HR5z9bzzAcgyo/W/2 0n277YOMiRL0XpoUJJByctWdIKTMN3ySOxUWU8B8OJnHtyG8Es4qLapi/iOczmv+zTa8 l6pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765238507; x=1765843307; 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=/4FW5co9+fSyaHV9OmjivazZbsmT2AI4p/mhxSPLytQ=; b=ON4DfGptCdf65Rs45b3/UWcDvmTKimMHAVlUktXa24od8pLGBEAtY8v6YnuZYhPlbX UWBKbYRyFG5T+2+jD/15uvHfhSK2z7YgX2ukHvYkeHu4F6PKKRbhdMbU0Lk08L2qlPNq 2899FeRSyLrfE/6vivG/4m6PA7aorI+KZ8zhUGBi+ugn5SZLQOQNZzn9JS71hdbNONsI RvdRpOgQ+RC2oCUqCoT3cZNrLzx4rAPMOhqNLW7Z0yM98EZZ1ZrkMmGgLd0vcZ2vs6HR GVSjOrR+AKNSridZ15r+bRFcy8eCSQU1ETMUWFAXqFkGnDLOFWHtneN25uLzaip8V1l9 YPMg== X-Gm-Message-State: AOJu0YwfNT921NscpHvWOHpc0FEOFN4vpfjF85zaCNGNP1oaqLDooj+E DB8fM2NPoP3WkTbcey/mPjg28qRvSv4H78blSlIDOhWOZLODTumO9mwCrRhXsvfPqrkLVQlBnzJ 9CXqcIoCMBl7fLMj9w8DIfdRVl126m5ldhEtRGJcFKsVX4DfCdmOM1nFN5DMFn1VgsRI6asN7Kp 5Il9AP/TsPRlpAIGSliM6DwYbH2DdGTWcgEmM= X-Google-Smtp-Source: AGHT+IFTTdaY/bSolEJp50dgI9jX5/kXhfC9u2JP9xvgnSkoSkmpNnWNxXOINQexKTETn9RpvVYKHiuXV5U= X-Received: from dybou4.prod.google.com ([2002:a05:7300:e5c4:b0:2a9:e065:7808]) (user=yubinz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:dd91:b0:2a4:3593:c7d1 with SMTP id 5a478bee46e88-2abc716505fmr4846252eec.17.1765238506760; Mon, 08 Dec 2025 16:01:46 -0800 (PST) Date: Tue, 09 Dec 2025 00:01:33 +0000 In-Reply-To: <20251209-aspeed-sgpio-v2-0-976e5f5790c2@google.com> Mime-Version: 1.0 References: <20251209-aspeed-sgpio-v2-0-976e5f5790c2@google.com> X-Mailer: b4 0.14.2 Message-ID: <20251209-aspeed-sgpio-v2-1-976e5f5790c2@google.com> Subject: [PATCH v2 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=36mY3aQYKCuUfbIPUgNVVNSL.JVTXLTb-KLcLSUVUNUb.VYN@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: 1765238567364158500 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 --- hw/gpio/aspeed_sgpio.c | 154 +++++++++++++++++++++++++++++++++++++= ++++ hw/gpio/meson.build | 1 + include/hw/gpio/aspeed_sgpio.h | 66 ++++++++++++++++++ 3 files changed, 221 insertions(+) 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')) 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 */ --=20 2.52.0.223.gf5cc29aaa4-goog From nobody Sun Dec 14 06:42:50 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=1765238539; cv=none; d=zohomail.com; s=zohoarc; b=GhmfSwArVrEW2fAqovS7R2WFgeLdnjdq0HehIO6L+mvWaMeYk8rWTABNgb+UOEJi7H/fAllHOtcZ+jyRStljlrWRjjJ6Ek526uE/KZKOen1/qXmYsCfI6uU7NrBYznC3lFvQlUI/aKGJW7/PCCnYz95ndpI2Lv6p2omVM9F5zWQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765238539; 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=+itFqe9iOClWFdQYPXiXyfRgN0EhEj+MWSAts2YlJwo=; b=Py2mY4yUZbibW/0e/WhTq8+B4DaME5cL69/0NqY1V/GSNH3WyhrQYPlWcEUVqELmMpizh8+yy5eBcZNuUZRbpNCCNWKiv96YQDrhMu2ZmbuCNk37tJ3bEar31GiA0mx45lklTet/zShBwDAXvJglFPH2UOZvT05no8HaWzUiGUI= 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 1765238539103795.5333310677855; Mon, 8 Dec 2025 16:02:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vSlAz-0007BS-9w; Mon, 08 Dec 2025 19:01: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 <37GY3aQYKCuchdKRWiPXXPUN.LXVZNVd-MNeNUWXWPWd.XaP@flex--yubinz.bounces.google.com>) id 1vSlAu-0007AM-9Y for qemu-devel@nongnu.org; Mon, 08 Dec 2025 19:01:52 -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 <37GY3aQYKCuchdKRWiPXXPUN.LXVZNVd-MNeNUWXWPWd.XaP@flex--yubinz.bounces.google.com>) id 1vSlAs-0007S6-9S for qemu-devel@nongnu.org; Mon, 08 Dec 2025 19:01:52 -0500 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-bc0de474d4eso11055603a12.0 for ; Mon, 08 Dec 2025 16:01:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765238508; x=1765843308; 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=+itFqe9iOClWFdQYPXiXyfRgN0EhEj+MWSAts2YlJwo=; b=iWkMmJJiaRis1j4QSPAoj8I7RvmVTQg2+NqhzU4n0apUSyZ7D28HkiRTJht3I+yG44 ed6a+ml+ihNQLyrOIMdz/4NGI2YSMxij3NUhQPImRLPhotIhklTH+epRj039Ho5OpXzU 9LnCs1OEVLJ51UG/ZhO2yKhG4raI5W/j7Z6cS9XzQqmLU84WwyIYzbywud6CSAfJaW/N OPYkb6+82s+JRJcmjPrBE64icvylzho+nHWSQKWNCvn7+7g14qSRRkYX8iWZySGsUTe1 g31arpvc0UP5Hx1aoajMKZyC6hcZRlgibc32zzUnbwTCIEUy9RaGKF9suDo+xrcR95IU n0XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765238508; x=1765843308; 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=+itFqe9iOClWFdQYPXiXyfRgN0EhEj+MWSAts2YlJwo=; b=KNQHB0dTaXaAOY9eKdY10yhkJSQlBx6BLxcO51kf3hq8sQnNENBmTphf2btTq83OlW zf5VPGlGneL0WViIXgzeUsrTrZWuhhhAqeRQge1mnVgKgNH0o2b7It+ZzYdnFmaD6MhA eB+AQtiN9562xUtqJ1e6Bex3LcM6QvodAjdlHPSjN34aVVILCYmGmmrlfBeQ6WTXaY9k yr0Sp9wBJwvo7BwMTbrec43cLDP0mmggraEaADnZeiufmO67IDH00xwS9QWd/4Ftf5+8 sPRlhTP7OCC9oBqoGevh9knwTl0WEUEVH3kwRHdQS5oNk9Vzois2whXVuHDqQjmbUA1h dxdg== X-Gm-Message-State: AOJu0YwkrM1P5gwzUfMcWrolm4iACYQBjxQhOBIUx7hWddlqQQgD3IIs LcORWmMRcxwXamg1b/dDe54dnfHP0bNgmdWbRmSU/KU6UlzOmiCvg84OV2p7NhxayE4utN1xfg3 2UirnG42bmC4eKfgEFxa0UPCaIKKiXup/LKmZq/hSw7ZcroE35CpLgRX6IzUIHp/c7SX49fTc7H CtxvZayqdydpu8DXxxhUPCoHrqgk9BVbUVHIo= X-Google-Smtp-Source: AGHT+IF2tu7LwmcUONnfMxXidevBRZBxTXYI9iD8VG//RH4XA96JSoELfsyN0MNVB0pmy9l+0XORFikNLSY= X-Received: from dlbpk8.prod.google.com ([2002:a05:7022:3848:b0:119:78ff:fe16]) (user=yubinz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:f81:b0:119:e56b:c74f with SMTP id a92af1059eb24-11e0315acc3mr6436240c88.20.1765238508206; Mon, 08 Dec 2025 16:01:48 -0800 (PST) Date: Tue, 09 Dec 2025 00:01:34 +0000 In-Reply-To: <20251209-aspeed-sgpio-v2-0-976e5f5790c2@google.com> Mime-Version: 1.0 References: <20251209-aspeed-sgpio-v2-0-976e5f5790c2@google.com> X-Mailer: b4 0.14.2 Message-ID: <20251209-aspeed-sgpio-v2-2-976e5f5790c2@google.com> Subject: [PATCH v2 2/6] hw/gpio/aspeed_sgpio: aspeed: 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::54a; envelope-from=37GY3aQYKCuchdKRWiPXXPUN.LXVZNVd-MNeNUWXWPWd.XaP@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=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: 1765238541253158500 Content-Transfer-Encoding: quoted-printable This commit adds QOM property accessors for the Aspeed SGPIO pins. 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..efa7e574abe87e33e58ac88dba5= e3469c6702b83 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%d", &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%d", &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%d", i); + object_property_add(obj, name, "bool", aspeed_sgpio_get_pin, + aspeed_sgpio_set_pin, NULL, NULL); + g_free(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.223.gf5cc29aaa4-goog From nobody Sun Dec 14 06:42:50 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=1765238568; cv=none; d=zohomail.com; s=zohoarc; b=aQ8w1jqWQGePQ4t2AOyYsV7M42bsRY2lAQCv4rFI3ugl63tA8AinAwrZbHgTfIGkmuS2AcG0Nz94jmztFrSm2T4ja4AtG0ecQLv0Ai1oaYBt0jr5B9HTnE+BrGhxSr0w/7Q2LV2+Avws5AjUaPhmzhSyn28Y1at4IrL7d6xU5VA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765238568; 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=GkfTGyYXl/bI9Qo5NKKOU3jJaNzHdmMmOtsv7lq1n3A=; b=Jwvzu2l3sHo4Kx0f0ycgx5GvlgzUIgCJxj+Bro6QcDKhMbx8mxYRzrQano4jXDoDAtu47KZTYbgJ1oO0VtG364qqIcyTSf10t1ckuUw+gz0B8Mvn/YMuivsT0RxC1kJ/8kUDoGbkFcn78U/gVJJfQAuczE2m4Z2B56MHZkmhjIs= 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 1765238568315620.1695475937505; Mon, 8 Dec 2025 16:02:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vSlB1-0007Gg-0I; Mon, 08 Dec 2025 19:01:59 -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 <37WY3aQYKCugieLSXjQYYQVO.MYWaOWe-NOfOVXYXQXe.YbQ@flex--yubinz.bounces.google.com>) id 1vSlAv-0007B9-TH for qemu-devel@nongnu.org; Mon, 08 Dec 2025 19:01:54 -0500 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <37WY3aQYKCugieLSXjQYYQVO.MYWaOWe-NOfOVXYXQXe.YbQ@flex--yubinz.bounces.google.com>) id 1vSlAt-0007SL-VI for qemu-devel@nongnu.org; Mon, 08 Dec 2025 19:01:53 -0500 Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-2958a134514so29919525ad.2 for ; Mon, 08 Dec 2025 16:01:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765238510; x=1765843310; 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=GkfTGyYXl/bI9Qo5NKKOU3jJaNzHdmMmOtsv7lq1n3A=; b=EEjQwPdBnF3Hes02WT4kYyMJqkzUmplzazkGqOm5HV39WpG0T0lCuNHghhV3JQd4xN 09OW4AyxyFIYfsKb8RO7SLP/uCx8DLWHXvw/QMECjWZTZNZhON+ClnUiUj/I/Ackezp6 aioLh8ge/4aPayZK3yre5KTXts50dzO7KO7pm1LhiRVb27RlzxFNKe1uHKCYXycqHor6 WAxjEAdxfTijQWnyoaTxeSb5yyL10P/3hzr3HIcN8QHEEwkE3hZzXHxhne1ShaLu0uOL 7bKHsnSPV8Nz31pZcnvMzMoE+4qeCXNKK1fdvPi4X5pt18wTSRkNA3rTsSVynwTJtZ3O 36LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765238510; x=1765843310; 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=GkfTGyYXl/bI9Qo5NKKOU3jJaNzHdmMmOtsv7lq1n3A=; b=L91H5wHYj7OwGN9f2phdJJ1nyw/hCfpl7y6a9gKnxPsyghYf7Nv1d17e18MMFhlg/k 9ZwoEmdmE1JhCLOfhlmhrgttHhnkb+t10tH7GppUMZiGhT6Loy4AdzupyHkvsU7h885b 3P68ogkd5J/lwkPFxJuGAuORkNLwLq0+r7yNkrSnHZuG65Qws8zYTMfieIuesRgvoLv7 N4vZmxAnZclRH+89X3ty7U0tT7h+kEHY2s66DAuz7J0V2E9Hh6KyxIB13HKHV9LxZLlD ydk0Mox77NHXGJ6f50ouDauTwJiEUY1OeWR+szg/19GFNER0UN69QStGsdDPz4p7gfVA rCUA== X-Gm-Message-State: AOJu0Yz2aNfvpr+PQ0lbshH5D66bLSF+dl/Gfe8cV4yuK6MUNRfgzsDu ydMocc8JZMIXkOHiqJDl9Zd6ygFL1nnmgT47pIPhg2a2ViCdbag6VXuvF5NKV2ktgoe2/8Mq6FE 8IMhvqkfve/Q7ZChU0WvAVFJW1nrl3Hl2mSFcoxVRYhajVr3MOxar/beAhSzNwcKZL4WljmdOx5 1oIfQAnSdpVU7L/srkUvl8ftcAiMpHhmChwOU= X-Google-Smtp-Source: AGHT+IE58N8SFqgvW7BUfqbvGpjaJuc2i8FUD03w3oS8sM9rWYaImx4I0HGAURN1jVbRI8CaAvOjBPkdTPI= X-Received: from dlk31.prod.google.com ([2002:a05:7022:11f:b0:11a:51f9:d69]) (user=yubinz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:248b:b0:11b:a514:b64f with SMTP id a92af1059eb24-11e031693eamr7000244c88.13.1765238509651; Mon, 08 Dec 2025 16:01:49 -0800 (PST) Date: Tue, 09 Dec 2025 00:01:35 +0000 In-Reply-To: <20251209-aspeed-sgpio-v2-0-976e5f5790c2@google.com> Mime-Version: 1.0 References: <20251209-aspeed-sgpio-v2-0-976e5f5790c2@google.com> X-Mailer: b4 0.14.2 Message-ID: <20251209-aspeed-sgpio-v2-3-976e5f5790c2@google.com> Subject: [PATCH v2 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::64a; envelope-from=37WY3aQYKCugieLSXjQYYQVO.MYWaOWe-NOfOVXYXQXe.YbQ@flex--yubinz.bounces.google.com; helo=mail-pl1-x64a.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=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: 1765238568852158500 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 --- hw/gpio/aspeed_sgpio.c | 126 +++++++++++++++++++++++++++++++++++++= ++-- include/hw/gpio/aspeed_sgpio.h | 2 + 2 files changed, 123 insertions(+), 5 deletions(-) diff --git a/hw/gpio/aspeed_sgpio.c b/hw/gpio/aspeed_sgpio.c index efa7e574abe87e33e58ac88dba5e3469c6702b83..ec5bc4e8351f89d86db0816fdd8= 75ff9b3c99cc1 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, 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]; }; --=20 2.52.0.223.gf5cc29aaa4-goog From nobody Sun Dec 14 06:42:50 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=1765238574; cv=none; d=zohomail.com; s=zohoarc; b=e5WOWrkMt9C+GMu+smlCbG8/BOWKaEScLQyX3SG1DaAxG8NRtIAIlZoV73R49Xal9Gi0LUF0yWLPSyDXFdjnhZCiiizPYbn+xWhj3VC6QiUPH+u13vIRrNO3hBuTq6aD/fmfN9Dy7+UMIVyEqKYvSJmsvFQ+hXukmFHo0fuu5/0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765238574; 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=WoZGW+0RXYZOQ7WbT8EW77f8UIHwQ46N9HiEFUyuaKg=; b=mVme+TtmQ4zak1cxtBPwrQt+2WOopbla0LdqSve86BU99VXBbrLXAXiTtHw8xKNV7CyruT8WFDfZLJodiG6Aa5G6SiIWAh28V63R07syRH0A6Lsdwx7s4OUdFPgPH3fuhMsWxp+t16FhH84yk4R0hjTisWpPcBnX6moEG72uJvk= 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 1765238574797379.42527263683246; Mon, 8 Dec 2025 16:02:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vSlB3-0007Ih-07; Mon, 08 Dec 2025 19:02:01 -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 <372Y3aQYKCuokgNUZlSaaSXQ.OaYcQYg-PQhQXZaZSZg.adS@flex--yubinz.bounces.google.com>) id 1vSlAw-0007BM-WF for qemu-devel@nongnu.org; Mon, 08 Dec 2025 19:01:56 -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 <372Y3aQYKCuokgNUZlSaaSXQ.OaYcQYg-PQhQXZaZSZg.adS@flex--yubinz.bounces.google.com>) id 1vSlAv-0007Sj-0r for qemu-devel@nongnu.org; Mon, 08 Dec 2025 19:01:54 -0500 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-b5edecdf94eso8543445a12.2 for ; Mon, 08 Dec 2025 16:01:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765238511; x=1765843311; 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=WoZGW+0RXYZOQ7WbT8EW77f8UIHwQ46N9HiEFUyuaKg=; b=okv7zSq7dYF/uLxN7Gimzjfda3xL/WSSvdF6bJuCeLA8P9Jpd5t5H85SviE6kSgRV3 Mp7Aoca7LaGsgHvmaoG9zIPe6qk168CZMGwgRX0kn73fQ4wVuLje+VAd7QmBhUeYNzHq C/uGM3qCoHAFk2tCrwYh9EO4RORMXq6ejVWWymaXL72ehv/vJWJ+TM+EU0AGF1Zfacg+ uQb74N3vaaI6pQ8geciwvXnxVQO1V9oxjxbsjVmKkWlokSHIX+CMhuqtm8Ywtzxz/w/I mioYBDKv4NuBaBrwlzN6GThFn0gGkvf2sRxIkXewDsLeuPCrO3ihCdCcOPRuK52R/Hzh MQzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765238511; x=1765843311; 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=WoZGW+0RXYZOQ7WbT8EW77f8UIHwQ46N9HiEFUyuaKg=; b=nHEyT9hlZzwgObVqSIJlMhZhPuw5JBHfxI5lZ6KX9o5v4e16S6RB9I2xbINCebWCUS yEqzGl8kLJ86SEXAaXAdVbzdXBjvBwPenbVQe1TRAvCJPtmRHbxkgX/1zoEDXMtXIfuF 7dpI1/q2oV6VGk/0yv2JMliZ+/+UwMBqcYa6QhJBrImmqocZefKjTwD/7xPoPHonQHI+ 022T8KuOqwGa4XClsdX/Na3a1HRVpqeRe1f06BCP6sO/cde16FxpYjiXBE6UmOO2S5Kg jLD/Y7u9NhqH6gjggRUvJ1JnfFCVoCj2PTCc96sBpnlDjYEJqjNS1JA1Y/IZBc+uincv GcIw== X-Gm-Message-State: AOJu0Yxh0PO+gcs1bK/RqCSNbAG0QhD5sE/Qersz6BQHxEqM2PnWHJcm GqEvZkFqbxx50M1b3jfQz66ILjFmMC+9j7lPPpM0fiaQoOx8Gqq7LUxckZyyXl5chHYr2S41ooR h95gEXLvVB+p1qBDG+8rLFjcy7p3gY1+HT4aAabxjkftI6lPDdSIRG7R1ikQ+mOreG5fuM6Ij89 AGG6UMdd0u1nK7nsxt44880ci+Tnk7Sozw/mA= X-Google-Smtp-Source: AGHT+IHp+L9AjjhHFhDta3VCFyRgIV5tizIbbgvDwbdEBPhqpRxvFPF1NVvFY3puDtyagemJ9FCKZnocMLo= X-Received: from dycng11.prod.google.com ([2002:a05:7300:ce0b:b0:2ab:8ef5:df8]) (user=yubinz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:db12:b0:2a4:61d1:f433 with SMTP id 5a478bee46e88-2abc71544e7mr3776456eec.16.1765238511220; Mon, 08 Dec 2025 16:01:51 -0800 (PST) Date: Tue, 09 Dec 2025 00:01:36 +0000 In-Reply-To: <20251209-aspeed-sgpio-v2-0-976e5f5790c2@google.com> Mime-Version: 1.0 References: <20251209-aspeed-sgpio-v2-0-976e5f5790c2@google.com> X-Mailer: b4 0.14.2 Message-ID: <20251209-aspeed-sgpio-v2-4-976e5f5790c2@google.com> Subject: [PATCH v2 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::549; envelope-from=372Y3aQYKCuokgNUZlSaaSXQ.OaYcQYg-PQhQXZaZSZg.adS@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=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: 1765238577026158500 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 Reviewed-by: C=C3=A9dric Le Goater --- hw/arm/aspeed_ast10x0.c | 6 +++--- hw/arm/aspeed_ast27x0.c | 10 ++++++++++ include/hw/arm/aspeed_soc.h | 8 ++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) 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; 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, --=20 2.52.0.223.gf5cc29aaa4-goog From nobody Sun Dec 14 06:42:50 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=1765238598; cv=none; d=zohomail.com; s=zohoarc; b=gvaskP1VtafEindeEb2dgV3GZffT6i3M+UalIvprzK7oiYWa0aeqyfVEN34vukmYp/IoCD3Cvu3Rzg2kCKBQjsVzsQPe/RrNxmlrXMUbSGfKZZOJZfVTWtliOUS/xjSsP7YJKqA+HN1OJKX+yllUSEn8czX7TaMc/adB1+iLinI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765238598; 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=otXfzV3x3jmdu0ev4HSkq2G8k4KXSOIhZQ6dmB3c07g=; b=CGDkGerUdt0eIEa6yGPHYoK6UA383oM/cebIgWO2ENT6XpQsupReDTvrTqS4UeAxfRvlEO45Un41Oni4p6XGyt7O04jkyeSaA1JEuxbtyLdsABv7cM8CDNSHLmBchjzLJ2CykZBkKk7Hj1/UKHM5dHGj6S/m9AX8cd68OvrSlwA= 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 17652385983455.204237389027298; Mon, 8 Dec 2025 16:03:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vSlB1-0007Gx-4o; Mon, 08 Dec 2025 19:01:59 -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 <38GY3aQYKCuslhOVamTbbTYR.PbZdRZh-QRiRYabaTah.beT@flex--yubinz.bounces.google.com>) id 1vSlAz-0007Bo-1j for qemu-devel@nongnu.org; Mon, 08 Dec 2025 19:01:57 -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 <38GY3aQYKCuslhOVamTbbTYR.PbZdRZh-QRiRYabaTah.beT@flex--yubinz.bounces.google.com>) id 1vSlAx-0007T6-KH for qemu-devel@nongnu.org; Mon, 08 Dec 2025 19:01:56 -0500 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-b99dc8f439bso9911192a12.2 for ; Mon, 08 Dec 2025 16:01:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765238513; x=1765843313; 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=otXfzV3x3jmdu0ev4HSkq2G8k4KXSOIhZQ6dmB3c07g=; b=tHSZFQE8o22Nc7gkV/pwUNh+VROd/trkXX8Sxptwm56alCfHaFn+mG4RRd8iU8lNnc NKWKOOu2ikxOW3ePSUdGvq/N/687w1irq8tEIX6hS3KH/UeK5bUjSnVy04Pdy4YCb1qD RFOCP+CoKMd5FAOXjE294SOwosy97cVsjnNOLyfhh78J2BIlZKaNVQ+Oxlb9ZXuYVQIO 03VMV8rh1F8N3HU7o0XfJdZGh4OF37QVPpWjM8gpZrGCN+6S/qwkQxiVtKlNbv2lRmka 1JZ4eyQBKGuYVxaRQc3pwkf/6h7P1KfPdXCrV6eixa0/ilkJgjpiObckaUGtOh1XobIf 0s6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765238513; x=1765843313; 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=otXfzV3x3jmdu0ev4HSkq2G8k4KXSOIhZQ6dmB3c07g=; b=R+mfRictmr2G3VrESy2JSUQtyGJsPaK3LkU4vhmory1o8rl8Eba7Q56JV71X/Kk6kf uRYspTgCMX+ZQaQHrvk6Ra83ODVre9KWX71h/ZxoZUqfXCkI8Nk53J2vUgIFqmh/QEVB jsH6aafo4ZIJ7rwf+ubc2NqPfYTm1xEh5EiIlR+wLWsuFzKIQDFKOdtuL5Quh+r3VOJT kqmnc18nWVs67Rtw3jKszUaOUb4C4zJsY/XB9syLaFUztqaPC8ryJqZqHLHOl5nR4aNa qgYwzhjImp0DCPUEes3ggsbs8J7vg/WcJoO5HQY1Xh2WwgnN8zXcRnl0mKoD9mp1R+b3 +pQA== X-Gm-Message-State: AOJu0YyAaQQ+xRNenzAHRgWaz3M9ERK/rwo8QJEFY8wszd+S0lThvCmk P3Dd5daDvvp242RqkKRqDSOmMbBAw6ZBUDA4nHgSyuXkNqWOSkwk/1Im/nZxCKIwzIczWUqEDno 2f4d8ahAL7Ymh7QuWWkF53CJuppKfrSO+7WoIdViN7BK5guS2C81iSwZYqp/N4cX1oPl/H08wsj EjCWhOaLFbeWzo6kk+ECGn+WAHSARwKahDnWc= X-Google-Smtp-Source: AGHT+IHW3z+q3GdQLsjhOzIktqrA/HPJHeruugQhUC1kIoFCNfbbRm7CFdSq4IdX37AW0pj/4rpbyL7ZwrU= X-Received: from dlbds7.prod.google.com ([2002:a05:7022:2507:b0:119:49ca:6b8b]) (user=yubinz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:492:b0:119:e569:fbb3 with SMTP id a92af1059eb24-11e032bab02mr8030968c88.34.1765238512653; Mon, 08 Dec 2025 16:01:52 -0800 (PST) Date: Tue, 09 Dec 2025 00:01:37 +0000 In-Reply-To: <20251209-aspeed-sgpio-v2-0-976e5f5790c2@google.com> Mime-Version: 1.0 References: <20251209-aspeed-sgpio-v2-0-976e5f5790c2@google.com> X-Mailer: b4 0.14.2 Message-ID: <20251209-aspeed-sgpio-v2-5-976e5f5790c2@google.com> Subject: [PATCH v2 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::54a; envelope-from=38GY3aQYKCuslhOVamTbbTYR.PbZdRZh-QRiRYabaTah.beT@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: 1765238599010158500 Content-Transfer-Encoding: quoted-printable This commit integrates the Aspeed SGPIO controller into the AST2700 Signed-off-by: Yubin Zou Reviewed-by: C=C3=A9dric Le Goater --- 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.223.gf5cc29aaa4-goog From nobody Sun Dec 14 06:42:50 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=1765238564; cv=none; d=zohomail.com; s=zohoarc; b=M3bkB3lRVCq9GHC7xEIizSUPTSlnMM5v9xNM/Op7iFVU5CNDxuiwMSt7k49S1NoCDeVn5auf/fAI4wZL9MeyFcC3aKeKA7IHz3CcSrftCI5xpCzGmCihwVN4yY/USwig2vDmZoEyXIFYszhBwNa3XmXDc/N1rh7mL4aHy1OMzlw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765238564; 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=bSakU68MOAqefQEVfQ70zw66AH6C0ci0Aetl72eSIF0=; b=RVRZOpHngROfnQfaKTkfJ/RHmkUFXouySjOp/PG1cHWJcdqIqgtSW59f0kTJkKyC7XmZWXqW+Ekvy7E+2es27UHDwMXHEi6r5oFiNCpWlLpwYMj54QRXIAsE5wkhX2u0a19CAhWHjCIQ2+P0r7BwNWsooiXB+fBN1Im3Do6IGsI= 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 176523856487958.062610628093694; Mon, 8 Dec 2025 16:02:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vSlBD-0007Nf-NQ; Mon, 08 Dec 2025 19:02:13 -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 <38mY3aQYKCu0njQXcoVddVaT.RdbfTbj-STkTacdcVcj.dgV@flex--yubinz.bounces.google.com>) id 1vSlB1-0007HD-BJ for qemu-devel@nongnu.org; Mon, 08 Dec 2025 19:01:59 -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 <38mY3aQYKCu0njQXcoVddVaT.RdbfTbj-STkTacdcVcj.dgV@flex--yubinz.bounces.google.com>) id 1vSlAz-0007Tf-GV for qemu-devel@nongnu.org; Mon, 08 Dec 2025 19:01:59 -0500 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-bddf9ce4931so8715847a12.0 for ; Mon, 08 Dec 2025 16:01:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765238515; x=1765843315; 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=bSakU68MOAqefQEVfQ70zw66AH6C0ci0Aetl72eSIF0=; b=preq52qJEpKzkWQBgPDZWi0x0BA/cXkWmc1spTvXESZkT1+9ZsOCjJk+gU675oAmkP MaEzozKwZ5+Ib42bDqhUTcNu9XlBAczr0Sb5duMbMFhS6aNHPK8eynpz4YjPRhPaJpv8 Fi3xAOIkim1oEA8NLoqnxhCeuENof2Cn9k5kfmCQMbSEA8Xa5gJRaaxX4niwy3cx5Pax 8yJ7pncl8bNuqgezRyQ85vBlCaVDJdHAmXIKNk2+JSieNp9Dt/YWZ8mi18IeguX7YhvM b73i+GEyilXa5N9/t1pCRXFOTV1ixFRGiPVoQtKs41YrH2kh30UTbAt/6oO/lpB132+u S6Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765238515; x=1765843315; 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=bSakU68MOAqefQEVfQ70zw66AH6C0ci0Aetl72eSIF0=; b=CkcJ8mpcSSvhKdGKGlfDdJy1klNwcPa+0swXnQ4xeB45KUxER+ya2Oo3SikfJyeK06 tIp4BUnAR4oK4FGvzsZ6VI4vxAlguw/icu1Dolfr5m1u4g3GkILaw/TEWjscXLCGLtWs Rylz5BwNATnmowQI5Uux+6X+/TBCLKEYzv85f/jiSDJBYPhhZPeE57dtxnISkNZ+Qrd5 8M5ZQBpsCfIJNYFqAFOh8Zb6QK9pekP8p1uE7a2tC0NpikmMeFjL/aZSj+3yG9sXTdl1 lv/GLckKoAUzVZERzsmbg6hKftMvnQkLZ8hM5CH83uZr1ieIdvgsDSa1bL0mNyVi7fZb 0QZg== X-Gm-Message-State: AOJu0YwPLRMcZOtBujFNzqzFMm0+CzAulOjuY95cDKloaTIbE9FMCrHa /OjEPgLMPxF/gy6V2B4XkcVeQFwW+tWPSMN6sxEbAtkonPWf1r8XnXcQgvSklRZ2D19gR/OGbgv rUQDN7n14pQ59rAYjBDPkGpgqPIQuyeoLgqJTNqA0mkLxmYWzqsOClaAp54XBUQxml5ssZi/Z+0 LN6ag9at9/QzDuNUZ9Ays1Twfz6R25NcMWI1w= X-Google-Smtp-Source: AGHT+IGcEWK2DdmZDYWJ9PxoE2Ys63+L/6KxbVLv8vENRgQEEbRnGZTn+n7vejWygrn/OSNwjxq3hrqtqZc= X-Received: from dycai1.prod.google.com ([2002:a05:7300:fb01:b0:2a4:63df:76a5]) (user=yubinz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:dd83:b0:2a4:63fb:c144 with SMTP id 5a478bee46e88-2abc7156465mr3649381eec.16.1765238514935; Mon, 08 Dec 2025 16:01:54 -0800 (PST) Date: Tue, 09 Dec 2025 00:01:38 +0000 In-Reply-To: <20251209-aspeed-sgpio-v2-0-976e5f5790c2@google.com> Mime-Version: 1.0 References: <20251209-aspeed-sgpio-v2-0-976e5f5790c2@google.com> X-Mailer: b4 0.14.2 Message-ID: <20251209-aspeed-sgpio-v2-6-976e5f5790c2@google.com> Subject: [PATCH v2 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=38mY3aQYKCu0njQXcoVddVaT.RdbfTbj-STkTacdcVcj.dgV@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: 1765238567338158500 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.223.gf5cc29aaa4-goog