From nobody Wed Dec 17 07:25:44 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=1765930980; cv=none; d=zohomail.com; s=zohoarc; b=n5jInyps3CPmSPnfaHUOcXnFSgZ5q2P1RuniqA+/bSyNWWxB/QqH4VPrdAObf+sA8RoWtaJJ+ShaljyJ6HWkLfb1BiJKBjaIHrhBaHGepkB4P58qLJGcXCiT7KXg1vL5e2zFnQFtylMFSoRsnLpuPLIWoL56PU+Vi822749mna8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765930980; 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=hDe5HoV/GZmqaxS0rl0d7vRs9gAIHRLH3csnZ8aXKbw=; b=deZCgSy9r6N/uW9m0CQ7yTCKYkeKsaEibLpxwhqMfFf8YLEmVhiPmzkN8p6a7Or/pfMQ2Kv0MKeWSs7nFANuG6mXEopGToWHIZLqU5voVTo7f+12s1iYDiYufj/hLTd39GfPvJQW/tWD3irQ3Trl65p237hzQgNus5q3/A2RWtc= 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 1765930980902739.7446037157175; Tue, 16 Dec 2025 16:23:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vVfJH-00067l-4H; Tue, 16 Dec 2025 19:22:31 -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 <3wPdBaQYKCgk73krw8pxxpun.lxvznv3-mn4nuwxwpw3.x0p@flex--yubinz.bounces.google.com>) id 1vVfJF-00064B-HM for qemu-devel@nongnu.org; Tue, 16 Dec 2025 19:22:29 -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 <3wPdBaQYKCgk73krw8pxxpun.lxvznv3-mn4nuwxwpw3.x0p@flex--yubinz.bounces.google.com>) id 1vVfJD-00055P-IW for qemu-devel@nongnu.org; Tue, 16 Dec 2025 19:22:29 -0500 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-b99f6516262so13743543a12.3 for ; Tue, 16 Dec 2025 16:22:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765930944; x=1766535744; 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=hDe5HoV/GZmqaxS0rl0d7vRs9gAIHRLH3csnZ8aXKbw=; b=iAoDAtGBGHB5vEzJe7uQTRvLEyzp8XM6SUzq1V7bw2+5xr8I64tHemP/2eaPCk5xA3 /XIm/FJNjHqs4wMKnnHdPPUPL9TaYXsoVEojb8OsBmzYpZsmmhEoPhV5J4Qm5HEwGzpS BHm0kZ6EiK7KeeMEIHoKIpQqYJCNSIRpif7/Nhq1idufjbSrioB62NDlROJeyeeuGSSc CT4dlDdyB1bDGGJcJ5EST5Wn6kCoZblT5u1J30vEtf0AXUub83MUcfap7tbi0XFzxOOa UYVvPgPFbqJMAJ3jDG9u4EeVI99jLkrQqjFbbvlNFqQnjB/sxKY6PIVVzndeATjmQCE/ x/DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765930944; x=1766535744; 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=hDe5HoV/GZmqaxS0rl0d7vRs9gAIHRLH3csnZ8aXKbw=; b=Zs2b9VwAFhOaUCTzUV7szXQjVRVBTn8AvoWSZj/tDva6M2qap6QiZZdU4cW+4fFP+1 v4K8xRaInRVf7SjReTUJuZR04mP4t/nch3qfAjWfm3e9HflRKhHkauyvC3dWRnYYND9z qXFwi/BtwPipkIUlmMjLibnpaLCUTpFy9iYWZBrJPjp7+5ctmGi3/ONj4p8/Ziz8vNON ujBhv/ncmv5pf4gdzMOCNbpXEZyTYr4Rp7VXSWHcq+HLPXWQg9bex4P0yzENDglcJot5 NYrxSY+4gO+sP/weCF26AZSedCD1yfR7FN/mZvjzgi8Rr80UtgsyIam6HjF7TLe4E4cw M3iw== X-Gm-Message-State: AOJu0YxRWvVvxdEi1FcPyWb0Yl3DVRZ3kH9NhAVnmdF9mdKdYoBrRbC9 Nbdi4HlhS5CGCvU2H6bHPJsgla4uvyMvyhUhMAZxLMAjVFIMwdaTWxXja22r67qTb8DneAV1ypc 9OqWtJaKQZudhKqs8UQMh/1CqJEpb64pRYOy1R+7IDfEYZVn4x2KPcrbN+Ag6jH6/hu+tplKp82 oNlnX5raNTj0WWogWPJfNF4aSjp7kVq6UEQLE= X-Google-Smtp-Source: AGHT+IFtChKgWe5so5wfqvZs9M3te9aL1ZW/NVDcItk4h+vakXtlgK5pjLE52ExIQNfndItwTpphqvJQ4yY= X-Received: from dlbds34.prod.google.com ([2002:a05:7022:2522:b0:11b:13:9d43]) (user=yubinz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:b886:b0:119:e56b:c75f with SMTP id a92af1059eb24-11f34c43869mr10872022c88.36.1765930944239; Tue, 16 Dec 2025 16:22:24 -0800 (PST) Date: Wed, 17 Dec 2025 00:22:11 +0000 In-Reply-To: <20251217-aspeed-sgpio-v4-0-28bbb8dcab30@google.com> Mime-Version: 1.0 References: <20251217-aspeed-sgpio-v4-0-28bbb8dcab30@google.com> X-Mailer: b4 0.14.2 Message-ID: <20251217-aspeed-sgpio-v4-1-28bbb8dcab30@google.com> Subject: [PATCH v4 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::54a; envelope-from=3wPdBaQYKCgk73krw8pxxpun.lxvznv3-mn4nuwxwpw3.x0p@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: 1765930984031158500 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 | 147 +++++++++++++++++++++++++++++++++++++= ++++ hw/gpio/meson.build | 1 + 3 files changed, 214 insertions(+) diff --git a/include/hw/gpio/aspeed_sgpio.h b/include/hw/gpio/aspeed_sgpio.h new file mode 100644 index 0000000000000000000000000000000000000000..60279a597c722f94fba406d60cb= 30a52ef9544bc --- /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 { + SysBusDeviceClass parent_class; + 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..3fc750fe619dcb6f9a1f2486999= e945002a6df13 --- /dev/null +++ b/hw/gpio/aspeed_sgpio.c @@ -0,0 +1,147 @@ +/* + * 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_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: + 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 ASPEED_SGPIO_MAX_PIN_PAIR; + 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.305.g3fc767764a-goog From nobody Wed Dec 17 07:25:44 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=1765930958; cv=none; d=zohomail.com; s=zohoarc; b=Q5HFc3uL9pmMQQNcTT1jwjJI1GXXNz9pOkRaRyXLFoHSHojNNSZSjlh3vYGbLuN1w+U3/Cq352Mh2yf9Q3IXln7rTS7ubtEZFzcM1pMdJDo1rDSRhA/YX/2Kznk6oJGDDsMb6RqtnpgZ7YydVzwUMoowX1xCNhj2lq7gtVuw+sA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765930958; 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=yfDqR2P/yB65lpiBOHOFUM1Gb+paknLpn22lMcn8yB8=; b=IeRZ0dcYEndSN7fyWyQqiHGS0bMV2yIuG/86pzbnnYGzCVabegnhJ2Ya/hU8cmOYerfKu2SxxxSR5HSmT/V8otgdCsqnbHe6T5IzKK6wmIicZub59cl8lJ4ie4pxkx8jfvKKbYEOhqeawuKG8rg2C21moAk+bwc5j7jWNVs0wXg= 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 1765930958950357.80006232007986; Tue, 16 Dec 2025 16:22:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vVfJH-00068j-Vp; Tue, 16 Dec 2025 19:22:32 -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 <3wfdBaQYKCgo84lsx9qyyqvo.myw0ow4-no5ovxyxqx4.y1q@flex--yubinz.bounces.google.com>) id 1vVfJF-00064f-O3 for qemu-devel@nongnu.org; Tue, 16 Dec 2025 19:22:29 -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 <3wfdBaQYKCgo84lsx9qyyqvo.myw0ow4-no5ovxyxqx4.y1q@flex--yubinz.bounces.google.com>) id 1vVfJD-00055w-V2 for qemu-devel@nongnu.org; Tue, 16 Dec 2025 19:22:29 -0500 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-bdced916ad0so8987540a12.0 for ; Tue, 16 Dec 2025 16:22:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765930946; x=1766535746; 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=yfDqR2P/yB65lpiBOHOFUM1Gb+paknLpn22lMcn8yB8=; b=C7dtk7F1E+bvvEz+txFxyvnm9FnJxN9Nn7QjNDiOdlimWLbSGrg66PquWfZpxM2tPD 1jQBZCmtdxHi8LambaBcMFGgVZ+tYyuVyzMgXNCgdmWOxaMkMSORnZgD4INnwzB2p8aU W9OiVThTwILezUpw/cWFvLhLyVJVfO/xHlOv9N5HIvCDDLScsta4xoSdB7HPh1YB+vDz Pv4B6rgQWdT6X9d4u+FKYVGhYVM9kxiVzbFQt0EJAk4mPJPsgpi4zE93Z+8v6KY4jqb0 MWw4d9g2pWb6nsaXWPiEs142DwZ4GXQc2MwJTvjm1jzdJGxGig/0VrsRw4dDiXh1r95w bh2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765930946; x=1766535746; 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=yfDqR2P/yB65lpiBOHOFUM1Gb+paknLpn22lMcn8yB8=; b=RtyDGyzzAgti6/mf4RUDdk7srYAwtcz2BMS1sWZCsjWxc/qZJhThxF0qbXxvR49HBt a6CTKqI3ijHU6ntdYf0t0zCJ5ZGRoUATx2nY990jnn8NDlc5kL19vlrRj+YFCe2cua/B LsSAYJwMJQ9osJDOJhJT9rc4LyU5Kol+7ZFVL/jgl7MQyh/oRj5qeANP62e5YkUWSCR3 eocbZBC1C26LSstzS7xcBbRiMC+AXZR8D1p1ET+qwablcZBDt3AlZRYbgb+zD+gHEBTY rdUueRv8ivmOaD8c5aDzj78N954dQoakMv30f/WF9WUDbZj9WZvIGQnxxN9GTlktxENT 3V5g== X-Gm-Message-State: AOJu0YwdpPvZqdEG6N+NVCDUELBnSDfwlgdcEU8NeabISblxeBbQbgGa 5oj3ETfacqpgFBxjO9oIG53ZC8PJz0K9X6gNHcpoGfMyY24l7Ws3osJb0tZavf8POzknXBKwseA eazG5oqISjWseRtwkBor9zaRdWFCk3HWe/oQwe7RDJwn7XuCajIKYNnp+9aUJs+vkUwobt3qwJd jjcxkyjQlvEm19KyE1kGS1xNs7vnb0gvdJSDU= X-Google-Smtp-Source: AGHT+IGUD0Sx1Bqe9Kf4r/U4t6wi4/KwVjB1s55bjWhftql49ZjbMJJLltld4G2AUeqYcMkKJ0hCVUoEHHw= X-Received: from dybna11.prod.google.com ([2002:a05:7300:cc0b:b0:2ac:2ddf:6eca]) (user=yubinz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:ff43:b0:2ac:19a3:c51c with SMTP id 5a478bee46e88-2ac2f8b1af5mr12015686eec.18.1765930945873; Tue, 16 Dec 2025 16:22:25 -0800 (PST) Date: Wed, 17 Dec 2025 00:22:12 +0000 In-Reply-To: <20251217-aspeed-sgpio-v4-0-28bbb8dcab30@google.com> Mime-Version: 1.0 References: <20251217-aspeed-sgpio-v4-0-28bbb8dcab30@google.com> X-Mailer: b4 0.14.2 Message-ID: <20251217-aspeed-sgpio-v4-2-28bbb8dcab30@google.com> Subject: [PATCH v4 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::54a; envelope-from=3wfdBaQYKCgo84lsx9qyyqvo.myw0ow4-no5ovxyxqx4.y1q@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: 1765930963325154100 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 | 77 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 77 insertions(+) diff --git a/hw/gpio/aspeed_sgpio.c b/hw/gpio/aspeed_sgpio.c index 3fc750fe619dcb6f9a1f2486999e945002a6df13..dc2df137db247c178adc05807bd= 0595fc0cb5c52 100644 --- a/hw/gpio/aspeed_sgpio.c +++ b/hw/gpio/aspeed_sgpio.c @@ -84,6 +84,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, @@ -107,6 +174,15 @@ 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++) { + g_autofree 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); + } +} + static void aspeed_sgpio_class_init(ObjectClass *klass, const void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -136,6 +212,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.305.g3fc767764a-goog From nobody Wed Dec 17 07:25:44 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=1765931030; cv=none; d=zohomail.com; s=zohoarc; b=CN1yFgFVSyd1WkToiQ5E/1+/6ZvoXmYjI99sXYkBEc9qPQkr5T/qH5kGp1fsftH8mGOvNkwCtRK20wzaEC2OosHGWXgeBLFcVONqd1+RR4SE0xXvmdGFsF/MJAb3xlEyhcorUKmIcorwmg1TUjN9o62Ct7iUBvhA9fmiMH7J65g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765931030; 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=vGB0XyTHQDzyvpib0uiRhOpgddVA0apqeuIWotN5Y1s=; b=fjCrSZZCJgclyvCukYHSFliB19UK1el3eLdK5YCLqMAyjjgjAO8LabPSyoFFaYGyw7H55/H0ZAPPxDfPLf7ZRzKqsHjsgBUcEBqgJXwKxbEQ05WzhTnLsx/qsZxo9+pb7vFpwXq1MoVt+uOEN3PKQOHWHYZNtvLDVLyaq8oxuKA= 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 1765931030429354.3973782274297; Tue, 16 Dec 2025 16:23:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vVfJL-0006BB-54; Tue, 16 Dec 2025 19:22:35 -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 <3w_dBaQYKCgwA6nuzBs00sxq.o0y2qy6-pq7qxz0zsz6.03s@flex--yubinz.bounces.google.com>) id 1vVfJH-00067q-9p for qemu-devel@nongnu.org; Tue, 16 Dec 2025 19:22:31 -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 <3w_dBaQYKCgwA6nuzBs00sxq.o0y2qy6-pq7qxz0zsz6.03s@flex--yubinz.bounces.google.com>) id 1vVfJF-00056F-GB for qemu-devel@nongnu.org; Tue, 16 Dec 2025 19:22:30 -0500 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-b62da7602a0so5599135a12.2 for ; Tue, 16 Dec 2025 16:22:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765930948; x=1766535748; 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=vGB0XyTHQDzyvpib0uiRhOpgddVA0apqeuIWotN5Y1s=; b=p9PN3mS9aYy8p+cdM0eAQf+qOjjUSoGWrknJJ4PFQw+8jGrV3epS8plp42Mgq5g8NL Gcxc0hUXx2Ho0ME9BxvGPiXJ5DnWRkPkH06TqSLtolh0fP8GFffk1Ju8P1g8fqTZbuxZ okWwpSDZR4LA22UtwTr/yAoIZFTTwZQHwlsV1v3fRVXgByIoyWB5Pb/b/WGRRB1FFBAb QO3eOp4PigjBpjXAqH37fanjaXp0SZz8RJib6KhwQBPSIhGSscSkSjp8vui8Al8nb6F/ sq2nF3rMzHI3CIR5CtgoBgqUK6DpwP1ze2COEmMQglpfDg+guxojKlbYJHdqssdNhdqj twLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765930948; x=1766535748; 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=vGB0XyTHQDzyvpib0uiRhOpgddVA0apqeuIWotN5Y1s=; b=jrfmIxzOGuHWycdDhbyp1znvGpXKedG1r2iZqpnd+0AxEKkPhs/YAx3OmVjyEAv1n1 vm8d1q2A3b4zsulUh4BhUW4ca6uc4lfbCkv/5Mp9DY8WuBhrJDX5wLvBtQoAwMDcUVbS dTclFXnLjSNNdp4rGT8aBBNK8/ltmqm2asT1c5GDGxgFhDm0Ytggbvvi/OWmx7UplG2O CBjBL+JW2ZEKIDVuhYhkDMcFbPccPrCGS6p1VQdemmhDE6fURja5yc0dwf8NQARsQSHy TvUvW4tUIdt7rRy+y+/KzUdWIWxx/7aoS/UIq8FbfJCEOLsYksMElbYJ/+DfMEosOA8S CNww== X-Gm-Message-State: AOJu0Yz3AS/bdgPj8Wo0uEgxtwXI95ff++40zoNzsWtgGG3OOFHSXmbp 3ZPkygkB0T4cwSRIW/EfgevROrFJ0uGnOlsJj38v5H3yRdl/lX9QnzVyd7D0NikG+qtVVvgPP8U hNoL/BX2mcQN9Ntc/o4caOPPVC4N0EKsnHRPSpFBSZDFGklX/eY8WCbuqZG2zOKUVAeYhhRuHts Fbwe/gzwzU6BKbAZvD9gZM5UZ0Y0pYGcoPU1o= X-Google-Smtp-Source: AGHT+IEbvKQ/uKYObY7njZsiQIr+/8H0J6Yqqn0Skj+Skh1+YXF3p39efyqIWbo6wBwcNHhsaj6sJJDUPwE= X-Received: from dlbrs5.prod.google.com ([2002:a05:7022:f685:b0:11d:d033:7c3a]) (user=yubinz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:170d:b0:11b:9386:825a with SMTP id a92af1059eb24-11f34c264d9mr8122078c88.47.1765930947376; Tue, 16 Dec 2025 16:22:27 -0800 (PST) Date: Wed, 17 Dec 2025 00:22:13 +0000 In-Reply-To: <20251217-aspeed-sgpio-v4-0-28bbb8dcab30@google.com> Mime-Version: 1.0 References: <20251217-aspeed-sgpio-v4-0-28bbb8dcab30@google.com> X-Mailer: b4 0.14.2 Message-ID: <20251217-aspeed-sgpio-v4-3-28bbb8dcab30@google.com> Subject: [PATCH v4 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=3w_dBaQYKCgwA6nuzBs00sxq.o0y2qy6-pq7qxz0zsz6.03s@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: 1765931033241154100 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 | 127 +++++++++++++++++++++++++++++++++++++= +++- 2 files changed, 127 insertions(+), 2 deletions(-) diff --git a/include/hw/gpio/aspeed_sgpio.h b/include/hw/gpio/aspeed_sgpio.h index 60279a597c722f94fba406d60cb30a52ef9544bc..8a11a9998c013cb2e4be99690ec= d7bcd9dcb5815 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 dc2df137db247c178adc05807bd0595fc0cb5c52..c6e6b3f52a9a982171a03cda820= a4573674ab67d 100644 --- a/hw/gpio/aspeed_sgpio.c +++ b/hw/gpio/aspeed_sgpio.c @@ -12,9 +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 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]; +} + + static uint64_t aspeed_sgpio_2700_read_control_reg(AspeedSGPIOState *s, uint32_t reg) { @@ -38,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, @@ -52,6 +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: + 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); @@ -116,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.305.g3fc767764a-goog From nobody Wed Dec 17 07:25:44 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=1765931039; cv=none; d=zohomail.com; s=zohoarc; b=O5xCrwD+3PzXUy9lhN+ZsLu5UGv9REr1PqgizSmXSHQQ83nGcoQgmqqc68fKjd7MzDH9dov7wWSQcEbG2OkX28B4BsuTt87EKHcsVGQlIn1BcyJk/Wb7+W+icHh9hOualYQXxyea1DksRYoAcKJe4V6IuyP3Ey4ZEmmxyA2fUuI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765931039; 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=pUzheFke4rBkSYqKKvOsbfaM/le++Z/ax6MSEjQSc2I=; b=U67HmnuM1KGGLNrFbcadGyIWE/l2Ry+zFxZl2jtIbI4f5msj9Aj+JYKHrWOi8K/GQltLqcPdzomWuHfbeScr8xNFMIgVtxdGNLu/0heWQ8Jn7N0liWf+h/moxEhKTh0qMy6hcHFjAbE3qIgflqN8QJ53MVK1WZBc91sanI+Rq54= 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 1765931039404438.53365417345344; Tue, 16 Dec 2025 16:23:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vVfJM-0006Br-Cl; Tue, 16 Dec 2025 19:22:36 -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 <3xPdBaQYKCg0B7ov0Ct11tyr.p1z3rz7-qr8ry010t07.14t@flex--yubinz.bounces.google.com>) id 1vVfJK-0006AV-Mq for qemu-devel@nongnu.org; Tue, 16 Dec 2025 19:22:34 -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 <3xPdBaQYKCg0B7ov0Ct11tyr.p1z3rz7-qr8ry010t07.14t@flex--yubinz.bounces.google.com>) id 1vVfJH-00056p-Qi for qemu-devel@nongnu.org; Tue, 16 Dec 2025 19:22:34 -0500 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-ba265ee0e34so5904934a12.2 for ; Tue, 16 Dec 2025 16:22:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765930949; x=1766535749; 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=pUzheFke4rBkSYqKKvOsbfaM/le++Z/ax6MSEjQSc2I=; b=px6acpMdG28Vmq3p2S21FC7vUb+6RoAZrN/ZWj6LWshKGqbUyXMpZLUW9T6w9xBVYm SLAQJ0RXTHQVWEmEim7oFmrS2TersVwChP/SOm4559ShfOQtIcSvw/wlSE5b6GmxMM5a mTK9UV9AumnqtXXXN4SBDCAeC+cUy5r9lQBssaW09uM1mWoXrILzPnLOEMkOUon/ce+i XVkpG36Ay4GSlfgvXehulnL6qgKviS337zX2GIezl/gs3htnCrrf3puEm+2gzQy5vPlN MlDk0vWaImJLqgNlWhl193VEVjnHkH4J359uj4+Ynszh5l8LV1z1z2OvQDMxVFxqdjte +sjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765930949; x=1766535749; 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=pUzheFke4rBkSYqKKvOsbfaM/le++Z/ax6MSEjQSc2I=; b=iQe5eJ3dFgJYtR8pT9OIzdgHfBZQrx0JivfuVjBMX1GF/n0mBnzG4NRSDPBuC2m74B CrioAn+8sAbLNrXoAk2kMk/V4n2S/GAbYTArAYyaQkjkQHz2ubM8JV4cPdZp2FJHpm/4 BaChjCiei/eatcKdLKEYn2pa4McjVBs350eGNU33mJ2kFeLtLZ4LVIgYiPrJ6U0/azj1 Bs+EmM8sERKwb5UHhMXvQFAkSQhn8ifs4WE6PsP2sQ69zGvFkfbGzUwr4aslAreR/ydS Lwd+o7dg2VF8zVagKYNbtqMLNT8EfzWRJYhfelT/hB2NTDSDBeO7UaLnhHx3JniwEiQW zzsA== X-Gm-Message-State: AOJu0Yy7iWQoFsH1QoWwQcCLjF9BzCSkKmjHtQ1B2ENQoIy2Tr1JcJeR YuN91kXZxs7vwkOfFpsiDJ9BVRMQmEWgcKKtaZX4EJ+7ZvEjGdhcEAKYm2OgY/3Fr2cZyG3hN0c swef6r1oucVN7hT6prw8y1nhANs5ae1lB7ArXeRWfnoPEVTunWxoCwLR1pfWJDa7+iENM6Po3Ef wK0FNckct/pSyJ4BPMoL+e23rJculTPrhBEf8= X-Google-Smtp-Source: AGHT+IF3dTIdC9vXJtJvAWF+HZ/O3dg1GgAfM6utnJgh/uwfeejn/t0F60OojnlRJPpdvuX8DmDA53RrDwk= X-Received: from dlbut7.prod.google.com ([2002:a05:7022:7e07:b0:11b:f588:7cbc]) (user=yubinz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:ec0b:b0:119:e56b:9899 with SMTP id a92af1059eb24-11f34850877mr12369957c88.0.1765930948986; Tue, 16 Dec 2025 16:22:28 -0800 (PST) Date: Wed, 17 Dec 2025 00:22:14 +0000 In-Reply-To: <20251217-aspeed-sgpio-v4-0-28bbb8dcab30@google.com> Mime-Version: 1.0 References: <20251217-aspeed-sgpio-v4-0-28bbb8dcab30@google.com> X-Mailer: b4 0.14.2 Message-ID: <20251217-aspeed-sgpio-v4-4-28bbb8dcab30@google.com> Subject: [PATCH v4 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=3xPdBaQYKCg0B7ov0Ct11tyr.p1z3rz7-qr8ry010t07.14t@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: 1765931041160154100 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.305.g3fc767764a-goog From nobody Wed Dec 17 07:25:44 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=1765931014; cv=none; d=zohomail.com; s=zohoarc; b=OmJkMff0aTN0NZnSum6IURMDtll/Bm/QjLhDlJnryG2HAvsbtE2IFRTBaX7B9244i/4ZIOGN20jRfQZkhps2lkbnqZoAXs1GQaHJJGVWeJ4tGA1dWXTHD7CtJWI5GUrBBy15o9z3VzKPr4cWuSEDXfHDRRnSQVRcFDWGkXKhvJU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765931014; 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=Td4DPCzbmgg72zwqL5xCqKX1wPVdbUHYL/gz2sAvTfU=; b=UaQQDYSkmvLhisbcv85t9MAn+UBBy3+l9+2okcAWp4MrbQJpkbUaobA85+gAGo9YX3tKny67HI+QDUo3lNbC+iW3wr4e1CZZW82wzHqu5P5tiS+zTWpx4mwFv0+hhdU/LXfkUzT9V4ahm994GEtLa6jOiEOjMbNbC9aALha74KY= 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 1765931014476688.2754653658852; Tue, 16 Dec 2025 16:23:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vVfJL-0006BE-NN; Tue, 16 Dec 2025 19:22:35 -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 <3xvdBaQYKCg8D9qx2Ev33v0t.r315t19-stAt0232v29.36v@flex--yubinz.bounces.google.com>) id 1vVfJK-0006AK-JN for qemu-devel@nongnu.org; Tue, 16 Dec 2025 19:22:34 -0500 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3xvdBaQYKCg8D9qx2Ev33v0t.r315t19-stAt0232v29.36v@flex--yubinz.bounces.google.com>) id 1vVfJI-00057D-Hi for qemu-devel@nongnu.org; Tue, 16 Dec 2025 19:22:34 -0500 Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-29efd658fadso148668845ad.0 for ; Tue, 16 Dec 2025 16:22:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765930951; x=1766535751; 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=Td4DPCzbmgg72zwqL5xCqKX1wPVdbUHYL/gz2sAvTfU=; b=RPPEczq2n5l5i0pSLuBGv4uYtwFWins6tCplnaIPDrk+u7C+maQqcynr2HUu6mysHh D0lf8BjzMTxmBNloYivBaHwVkoKmf7qy15XZ5+7i1GjoLSJQmFj/ioW97X3gReMamElg WYv2A3wyxFr9jb2cOkyXiEXgB8O1+owivceBc4rj3Dt3ugp0JwDa6epiAFlzMBW5Ffhl cqVBIBbPoDDXiIhmWxTNmt/flB7VjtOCw9be25HE/q04PsR2g5BDN61e4jasUSEWmpsI gg1IFkeBSGfu+P4M0ytoe05SmQw0moxsYcZA7J6BEeAOzoTH7+a7BpHDlLd+x1dXcM/o cGig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765930951; x=1766535751; 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=Td4DPCzbmgg72zwqL5xCqKX1wPVdbUHYL/gz2sAvTfU=; b=OIHB01hXebwdQxMx5m7rbDPf/QrBSkRwy/yMNQx6Dzc8Zm9Op5hORm1ln4bC8FJdvM PgtcarMknew5XzPUtTAOV6wJQ2ykk6wNkP75ByRBIuywpyZ1mCc9bH1qGEEMKodPD4dH PENLgUAXWxoX6zC3jP2Yx3B/lQOwCNaNUIEtvXjysRtMSU2OJENRByxlN4lIqB93Dy5F Gkrls9CUaUdrEglgqgaFtqUVTA2pxxeibXo8NhWaJckt5y65z2fTSBCdbjrCq/qPIE3m L/tpMNc2kMGmMrxGxjbvT+2MXDDms1A73eok00LvUPPcnuQo3t2SfHyq+2j0n/0Q9K7S gaIQ== X-Gm-Message-State: AOJu0YzyY50/zQs7bKhaM6AqijE8YXNKbfcnS9Nvxh7KHN7wdAaImxAS RKEYRd22Kii9tgQBY6h4SYvLk+UZzBwBt5+0ljT2jNdzSXcSZhQTaRYAvpHVfJkpKnj8QeiLG3f G5xGgplAB3PgD21u07awgnHNNNMllwNtNaUs3uo1Vzf4Fll8VEpLl91d+ba/XX3KNkFCVDLTphS YBG3MxPXGr2gXohiRlEjOlS3KEStrYaxnq+K4= X-Google-Smtp-Source: AGHT+IFjkpWaeGVncAoFTTO807u93JYuLeP+c1BJKbTKFlVaUeXXnwO1BXykUZZRfotUaZ+eSqTwjS9Rms4= X-Received: from dyaf27-n1.prod.google.com ([2002:a05:693c:839b:10b0:2a9:83e7:2680]) (user=yubinz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:d197:b0:2a4:3593:6474 with SMTP id 5a478bee46e88-2ac30120ab9mr11104971eec.36.1765930950560; Tue, 16 Dec 2025 16:22:30 -0800 (PST) Date: Wed, 17 Dec 2025 00:22:15 +0000 In-Reply-To: <20251217-aspeed-sgpio-v4-0-28bbb8dcab30@google.com> Mime-Version: 1.0 References: <20251217-aspeed-sgpio-v4-0-28bbb8dcab30@google.com> X-Mailer: b4 0.14.2 Message-ID: <20251217-aspeed-sgpio-v4-5-28bbb8dcab30@google.com> Subject: [PATCH v4 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::649; envelope-from=3xvdBaQYKCg8D9qx2Ev33v0t.r315t19-stAt0232v29.36v@flex--yubinz.bounces.google.com; helo=mail-pl1-x649.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=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: 1765931015897158500 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.305.g3fc767764a-goog From nobody Wed Dec 17 07:25:44 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=1765931015; cv=none; d=zohomail.com; s=zohoarc; b=P8KJ4MEh/cLbWAIrPorCjWMarZBkPM8Jdt6lhmqP4chUqlWpMUTe/760+Bd9wA1ibz2eypFJZGx/NPqms7mRF3cj1l3nOgkEPEUQm0HBGTbtUIzshkwsFPQFseLXdL7W9utEmUsyg+CIZcfblhg4wDxTaGa8QjC+kKQQ+NuB2d4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1765931015; 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=wtQWpzqrkzhQ62X+JBS6XXEpmyy4naPMlbQEjR9jrn0=; b=mD7/LN4fNW7fMyivm71F+bYi5TzRMCkmnKpC0dNyGlWNsOSzkAi/+zs1/oQlY1TFJnBAjoAe7WHOEq2hqIvd1YpPkt9lmQ7GQG3Yh6Av5iebNGGJU0wVXSQBgAEDqxViWnegXHJdsOgKeE53Eq/JfWQgUH8CB2UgOotEQLlgwag= 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 1765931015011401.048293339305; Tue, 16 Dec 2025 16:23:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vVfJN-0006FE-LU; Tue, 16 Dec 2025 19:22:37 -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 <3x_dBaQYKChAEAry3Fw44w1u.s426u2A-tuBu1343w3A.47w@flex--yubinz.bounces.google.com>) id 1vVfJM-0006Bb-0l for qemu-devel@nongnu.org; Tue, 16 Dec 2025 19:22:36 -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 <3x_dBaQYKChAEAry3Fw44w1u.s426u2A-tuBu1343w3A.47w@flex--yubinz.bounces.google.com>) id 1vVfJJ-00057U-UW for qemu-devel@nongnu.org; Tue, 16 Dec 2025 19:22:35 -0500 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-be8c77ecc63so7900259a12.2 for ; Tue, 16 Dec 2025 16:22:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765930952; x=1766535752; 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=wtQWpzqrkzhQ62X+JBS6XXEpmyy4naPMlbQEjR9jrn0=; b=gsiLeqAZl6ZmlGabVDI/gybhQOpx4IL5Tut2mNRhYfUDpJOtgoL6victEVZ1q7Yi82 jXHp8QRMobFO8udI5TlhbVSNJSXe54EAib9loIisS3RDutQ5lwUHdlxcXkCw8Zb5e0TT mOdgE3tVViFWaX/NGlPsSBmLlUeexf60LkUIfJfaiErpb+JLsWl1UIl1AcNFkLHs5DWy B461bIcCtHSH1IPMZ0QTbedVAMA2ictm6pntqMpA+uNsEH094fMfYNQ/dZPGgQlhlS0x tuQJlNlTbvwTkm8EW7EDamYp9IbAZozXNkIl/1Kz4w21iPis1ITu0k3N8dg93IotUf7u 1qhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765930952; x=1766535752; 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=wtQWpzqrkzhQ62X+JBS6XXEpmyy4naPMlbQEjR9jrn0=; b=DI5vUZzxJHwlBfFM6yE8LSVfG9FYo2C92lCslGxTrAQwTWD6IDsgD4WFdOAcL8iyqA TaNJe6JdsDPEePbBe4HoQUw2R40hRBVd+8+NmLxxNhg9Ks442FXhBP+pocDsq9YuD9U2 WzLZuIBsPAwbYX9VZRaPKiBywcdCmDNz3InHYjhug2+X6s8WeCtzgty4N1/wyNsk9m1W c1FYFA8iygiN+5LPazRDdYHq9Z3rDkT/h67J2ykNgbqVtxnsG0m+WGsUv7wlRpmNqgdu NxiEv9eoGbhwMYKYtZiTvM6Ev20G7H1Lhe7sQEaF7PWnIFhWTTmBvOnh7yBERpbZ7aau R6Hg== X-Gm-Message-State: AOJu0Yyz55q05qrFBJGC24l9N478lNIjPVQRRkrMOeXTAaeChZrGuHmz rPQeEaOklnVf9vbUg22q0KS0d9pyIq5ia3FVAuzdYSJ9HAJc1gzdzJs0CtFdV4pR6G02FGfbN5G pSY76bl0Ff00gPm5vGQJ6NlHI/WDO9Qc8Yhu5gHmltDGZ1pj0YW8UyID4Nb72oEsfhuW7uE6cLm UBHDk5CSA2F402aMn9h2RNhSLPF4T/yMLIpHU= X-Google-Smtp-Source: AGHT+IEG8k0gCHTMNfEWpaLqJ0elZtTAghdcAuWHvpsKErFfzwRLNTcp5x//myYMQ+oPQCtHpXiSVfpwW/0= X-Received: from dlbcm18.prod.google.com ([2002:a05:7022:6892:b0:11f:3fcf:58c]) (user=yubinz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:3a8e:b0:11a:44d1:533a with SMTP id a92af1059eb24-11f349c54ddmr12856072c88.12.1765930951993; Tue, 16 Dec 2025 16:22:31 -0800 (PST) Date: Wed, 17 Dec 2025 00:22:16 +0000 In-Reply-To: <20251217-aspeed-sgpio-v4-0-28bbb8dcab30@google.com> Mime-Version: 1.0 References: <20251217-aspeed-sgpio-v4-0-28bbb8dcab30@google.com> X-Mailer: b4 0.14.2 Message-ID: <20251217-aspeed-sgpio-v4-6-28bbb8dcab30@google.com> Subject: [PATCH v4 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=3x_dBaQYKChAEAry3Fw44w1u.s426u2A-tuBu1343w3A.47w@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: 1765931016949154100 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 | 166 +++++++++++++++++++++++++++++++++++= ++++ tests/qtest/meson.build | 1 + 2 files changed, 167 insertions(+) diff --git a/tests/qtest/ast2700-sgpio-test.c b/tests/qtest/ast2700-sgpio-t= est.c new file mode 100644 index 0000000000000000000000000000000000000000..6d024524a32717560301f73ee1c= 7132f4181e711 --- /dev/null +++ b/tests/qtest/ast2700-sgpio-test.c @@ -0,0 +1,166 @@ +/* + * QTest testcase for the ASPEED AST2700 SGPIO Controller. + * + * SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (C) 2025 Google LLC. + */ + +#include "qemu/osdep.h" +#include "qemu/bitops.h" +#include "qobject/qdict.h" +#include "libqtest-single.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%03d", 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%03d", 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%03d", 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_ast_2700_sgpio_input(void) +{ + test_input_pins("-machine ast2700-evb", + AST2700_SGPIO0_BASE, 0); + test_input_pins("-machine ast2700-evb", + AST2700_SGPIO1_BASE, 1); +} + +static void test_ast_2700_sgpio_output(void) +{ + 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); +} + +static void test_ast_2700_sgpio_irq(void) +{ + 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/ast_2700_sgpio_input", + test_ast_2700_sgpio_input); + qtest_add_func("/ast2700/sgpio/ast_2700_sgpio_output", + test_ast_2700_sgpio_output); + qtest_add_func("/ast2700/sgpio/ast_2700_sgpio_irq", + test_ast_2700_sgpio_irq); + + 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.305.g3fc767764a-goog