From nobody Fri Apr 19 02:05:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1663713632; cv=none; d=zohomail.com; s=zohoarc; b=NWuLIg2YGOZmhcK1kepgurGRT4WljhnJydfBJ/41SezyCoQ5FjHEZ6Ss76rVjbESvEhumRduRZ1GUDgMT40x38bilUG79y3XjJ6ZrGA0N3P9MP6AOKbkY962dSEM9qG+3Pss+504rkNQm0OX4y5qE0cFKLs/hPf8N3GGRMd88+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663713632; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BkN0v0ZPP63Cq9RhTuOZT0vrTdJqzyTY4NgyNGv1bT8=; b=S8TNesp5GVRnbZ56LmhTCmonOE+MI7NbnCm3o6jdhzjJ8i7PsVShR3kCtDtCsHYDsXgpIW/E8BHZ01lMXOWBb/z3iFiH9lx0xvVxXgEgDiom9EnZ03vs9xlhIHhZxuyj4xYafbuDV8KBnvWTUyym90TPnUW37OzYQYTzYy13NAw= 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=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1663713632851985.9551648563752; Tue, 20 Sep 2022 15:40:32 -0700 (PDT) Received: from localhost ([::1]:57896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oalup-0002Ni-Nv for importer@patchew.org; Tue, 20 Sep 2022 18:40:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oaiGX-0004RM-TB for qemu-devel@nongnu.org; Tue, 20 Sep 2022 14:46:51 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:45718) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oaiGS-0007QI-F4 for qemu-devel@nongnu.org; Tue, 20 Sep 2022 14:46:40 -0400 Received: by mail-pl1-x62c.google.com with SMTP id w20so3276228ply.12 for ; Tue, 20 Sep 2022 11:46:32 -0700 (PDT) Received: from localhost ([49.7.199.180]) by smtp.gmail.com with ESMTPSA id y129-20020a62ce87000000b005480167b921sm224810pfg.172.2022.09.20.11.46.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 11:46:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=BkN0v0ZPP63Cq9RhTuOZT0vrTdJqzyTY4NgyNGv1bT8=; b=pbZVtQoZctznEkUDonMjdTGgxode2S8ruXdS4GCR7IvZZx6M8VpS3vzrYQFDL0XYWi r8dlh3IIO/JsPcLEhtRvDeOeQouFYd+wO2SNH4PxkqZcr6FFYIbQ2xnqShIkmHtZeRvo rzszIFV6kFkv1rXk1uuMVRdkKGrY3Z0v26TScXvPI2oLDuArnt2OFilspXuIi75fQK9r O08wpQcP39kMG/w/yjG2VFA58AUHvYv7iZYczJ+wyVR8AK1fXeVDGzfGUeUQsSW37E/d YBkgiAqI/aut5W3wczWtE9HxX/uvyIC0csPL2waGtRkCgmUk/khUlZz8xCjtif7XcdPj tSNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=BkN0v0ZPP63Cq9RhTuOZT0vrTdJqzyTY4NgyNGv1bT8=; b=RE+aue/B/cMvmdy1PTKHRHI5QSRzDk1KS4W9TAkfoW/HIDdFTk0Pc1z4Uf78jCO0qG HV+iGY0FQBrmwpoacZHi4y1k2DmiL/6CFe3diuZWrp9QJU3LT2xi+3pABtxQOTO2HPLc tSJFG2N/SrDh7sgVEqUHIlUpF6Kxe20u8DYGutGEgdljpRYbJV83IGknYoP5Ns6jDenu TNmLBRRtS45MnGfVkghzuR0xnQ2IgiCiapO/x6AvPuBSlxrqDn5U4Hd5ocpHERSFsrGF JT7Aghcljb8xpEVArHursBk2qFFp1k+DhxqdHAEqvQ6rjos50pMlYLxCocwHrNUiWkHx rNjg== X-Gm-Message-State: ACrzQf02cc7suCZ1o8vxkSAJB6AhazOBX8eSDaKn459JgHk3v6E3nvHB nGthvCHpyWz4L1BAyWCiUj77Gw== X-Google-Smtp-Source: AMsMyM7JMrSPDGZ1OMpeJYyZh9ISGLuvgRZBOe3ydLO4MjOXYmSVkOLDEZMtPHht+xDFHq68Rjg7SQ== X-Received: by 2002:a17:902:ea11:b0:178:f0a:7472 with SMTP id s17-20020a170902ea1100b001780f0a7472mr992875plg.46.1663699591649; Tue, 20 Sep 2022 11:46:31 -0700 (PDT) From: Jian Zhang To: f4bug@amsat.org, peter.maydell@linaro.org, clg@kaod.org, andrew@aj.id.au, joel@jms.id.au, qemu-devel@nongnu.org, qemu-arm@nongnu.org Cc: yulei.sh@bytedance.com, tangyiwei.2022@bytedance.com, chentingting.2150@bytedance.com, yuhao.17@bytedance.com, wangxiaohua.1217@bytedance.com, xiening.xll@bytedance.com Subject: [PATCH v2 1/3] hw/misc/latching_switch: Add a simple latching_switch device Date: Wed, 21 Sep 2022 02:46:17 +0800 Message-Id: <20220920184619.3370115-2-zhangjian.3032@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220920184619.3370115-1-zhangjian.3032@bytedance.com> References: <20220920184619.3370115-1-zhangjian.3032@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=zhangjian.3032@bytedance.com; helo=mail-pl1-x62c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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" X-ZohoMail-DKIM: pass (identity @bytedance-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1663713634570100001 Content-Type: text/plain; charset="utf-8" Implement a simple latching switch device. The latching switch is a switch that can be turned on and off. When the input new state and match the trigger edge, the switch state will be toggled. This device privide 2 properties `state(bool)` and `trigger-edge(string)`, and 2 gpios `input` and `output`. The `state` property is the initial state of the switch, and the `trigger-e= dge` property is the edge that will trigger the switch state to be toggled, the value can be `rising`, `falling` or `both`. Signed-off-by: Jian Zhang --- MAINTAINERS | 2 + hw/misc/Kconfig | 3 + hw/misc/latching_switch.c | 212 ++++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + include/hw/misc/latching_switch.h | 56 ++++++++ 5 files changed, 274 insertions(+) create mode 100644 hw/misc/latching_switch.c create mode 100644 include/hw/misc/latching_switch.h diff --git a/MAINTAINERS b/MAINTAINERS index 1729c0901c..0b252a9339 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1066,6 +1066,8 @@ F: include/hw/net/ftgmac100.h F: docs/system/arm/aspeed.rst F: tests/qtest/*aspeed* F: hw/arm/fby35.c +F: include/hw/misc/latching_switch.h +F: hw/misc/latching_switch.c =20 NRF51 M: Joel Stanley diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig index cbabe9f78c..96345c6456 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -139,6 +139,9 @@ config UNIMP config LED bool =20 +config LATCHING_SWITCH + bool + config MAC_VIA bool select MOS6522 diff --git a/hw/misc/latching_switch.c b/hw/misc/latching_switch.c new file mode 100644 index 0000000000..03ce40b77c --- /dev/null +++ b/hw/misc/latching_switch.c @@ -0,0 +1,212 @@ +/* + * QEMU single Latching Switch device + * + * Copyright (C) 2022 Jian Zhang + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qapi/visitor.h" +#include "migration/vmstate.h" +#include "hw/qdev-properties.h" +#include "hw/irq.h" +#include "hw/misc/latching_switch.h" +#include "trace.h" + +static void toggle_output(LatchingSwitchState *s) +{ + s->state =3D !(s->state); + qemu_set_irq(s->output, !!(s->state)); +} + +static void input_handler(void *opaque, int line, int new_state) +{ + LatchingSwitchState *s =3D LATCHING_SWITCH(opaque); + + assert(line =3D=3D 0); + + if (s->trigger_edge =3D=3D TRIGGER_EDGE_FALLING && new_state =3D=3D 0)= { + toggle_output(s); + } else if (s->trigger_edge =3D=3D TRIGGER_EDGE_RISING && new_state =3D= =3D 1) { + toggle_output(s); + } else if (s->trigger_edge =3D=3D TRIGGER_EDGE_BOTH) { + toggle_output(s); + } +} + +static void latching_switch_reset(DeviceState *dev) +{ + LatchingSwitchState *s =3D LATCHING_SWITCH(dev); + /* reset to off */ + s->state =3D false; + /* reset to falling edge trigger */ + s->trigger_edge =3D TRIGGER_EDGE_FALLING; +} + +static const VMStateDescription vmstate_latching_switch =3D { + .name =3D TYPE_LATCHING_SWITCH, + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_BOOL(state, LatchingSwitchState), + VMSTATE_U8(trigger_edge, LatchingSwitchState), + VMSTATE_END_OF_LIST() + } +}; + +static void latching_switch_realize(DeviceState *dev, Error **errp) +{ + LatchingSwitchState *s =3D LATCHING_SWITCH(dev); + + /* init a input io */ + qdev_init_gpio_in(dev, input_handler, 1); + + /* init a output io */ + qdev_init_gpio_out(dev, &(s->output), 1); +} + +static void latching_switch_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->desc =3D "Latching Switch"; + dc->vmsd =3D &vmstate_latching_switch; + dc->reset =3D latching_switch_reset; + dc->realize =3D latching_switch_realize; + set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); +} + +static void latching_switch_get_state(Object *obj, Visitor *v, const char = *name, + void *opaque, Error **errp) +{ + LatchingSwitchState *s =3D LATCHING_SWITCH(obj); + bool value =3D s->state; + + visit_type_bool(v, name, &value, errp); +} + +static void latching_switch_set_state(Object *obj, Visitor *v, const char = *name, + void *opaque, Error **errp) +{ + LatchingSwitchState *s =3D LATCHING_SWITCH(obj); + bool value; + Error *err =3D NULL; + + visit_type_bool(v, name, &value, &err); + if (err) { + error_propagate(errp, err); + return; + } + + if (value !=3D s->state) { + toggle_output(s); + } +} +static void latching_switch_get_trigger_edge(Object *obj, Visitor *v, + const char *name, void *opaqu= e, + Error **errp) +{ + LatchingSwitchState *s =3D LATCHING_SWITCH(obj); + int value =3D s->trigger_edge; + char *p =3D NULL; + + if (value =3D=3D TRIGGER_EDGE_FALLING) { + p =3D g_strdup("falling"); + visit_type_str(v, name, &p, errp); + } else if (value =3D=3D TRIGGER_EDGE_RISING) { + p =3D g_strdup("rising"); + visit_type_str(v, name, &p, errp); + } else if (value =3D=3D TRIGGER_EDGE_BOTH) { + p =3D g_strdup("both"); + visit_type_str(v, name, &p, errp); + } else { + error_setg(errp, "Invalid trigger edge value"); + } + g_free(p); +} + +static void latching_switch_set_trigger_edge(Object *obj, Visitor *v, + const char *name, void *opaqu= e, + Error **errp) +{ + LatchingSwitchState *s =3D LATCHING_SWITCH(obj); + char *value; + Error *err =3D NULL; + + visit_type_str(v, name, &value, &err); + if (err) { + error_propagate(errp, err); + return; + } + + if (strcmp(value, "falling") =3D=3D 0) { + s->trigger_edge =3D TRIGGER_EDGE_FALLING; + } else if (strcmp(value, "rising") =3D=3D 0) { + s->trigger_edge =3D TRIGGER_EDGE_RISING; + } else if (strcmp(value, "both") =3D=3D 0) { + s->trigger_edge =3D TRIGGER_EDGE_BOTH; + } else { + error_setg(errp, "Invalid trigger edge type: %s", value); + } +} + +static void latching_switch_init(Object *obj) +{ + LatchingSwitchState *s =3D LATCHING_SWITCH(obj); + + s->state =3D false; + s->trigger_edge =3D TRIGGER_EDGE_FALLING; + + object_property_add(obj, "state", "bool", + latching_switch_get_state, + latching_switch_set_state, + NULL, NULL); + object_property_add(obj, "trigger-edge", "string", + latching_switch_get_trigger_edge, + latching_switch_set_trigger_edge, + NULL, NULL); +} + +static const TypeInfo latching_switch_info =3D { + .name =3D TYPE_LATCHING_SWITCH, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(LatchingSwitchState), + .class_init =3D latching_switch_class_init, + .instance_init =3D latching_switch_init, +}; + +static void latching_switch_register_types(void) +{ + type_register_static(&latching_switch_info); +} + +type_init(latching_switch_register_types); + +LatchingSwitchState *latching_switch_create_simple(Object *parentobj, + bool state, + uint8_t trigger_edge) +{ + static const char *name =3D "latching-switch"; + DeviceState *dev; + + dev =3D qdev_new(TYPE_LATCHING_SWITCH); + + qdev_prop_set_bit(dev, "state", state); + + if (trigger_edge =3D=3D TRIGGER_EDGE_FALLING) { + qdev_prop_set_string(dev, "trigger-edge", "falling"); + } else if (trigger_edge =3D=3D TRIGGER_EDGE_RISING) { + qdev_prop_set_string(dev, "trigger-edge", "rising"); + } else if (trigger_edge =3D=3D TRIGGER_EDGE_BOTH) { + qdev_prop_set_string(dev, "trigger-edge", "both"); + } else { + error_report("Invalid trigger edge value"); + exit(1); + } + + object_property_add_child(parentobj, name, OBJECT(dev)); + qdev_realize_and_unref(dev, NULL, &error_fatal); + + return LATCHING_SWITCH(dev); +} diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 95268eddc0..23b5c7f69e 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -9,6 +9,7 @@ softmmu_ss.add(when: 'CONFIG_SGA', if_true: files('sga.c')) softmmu_ss.add(when: 'CONFIG_UNIMP', if_true: files('unimp.c')) softmmu_ss.add(when: 'CONFIG_EMPTY_SLOT', if_true: files('empty_slot.c')) softmmu_ss.add(when: 'CONFIG_LED', if_true: files('led.c')) +softmmu_ss.add(when: 'CONFIG_LATCHING_SWITCH', if_true: files('latching_sw= itch.c')) softmmu_ss.add(when: 'CONFIG_PVPANIC_COMMON', if_true: files('pvpanic.c')) =20 # ARM devices diff --git a/include/hw/misc/latching_switch.h b/include/hw/misc/latching_s= witch.h new file mode 100644 index 0000000000..de1d9d27a4 --- /dev/null +++ b/include/hw/misc/latching_switch.h @@ -0,0 +1,56 @@ +/* + * QEMU single Latching Switch device + * + * Copyright (C) Jian Zhang + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef HW_MISC_LATCHING_SWITCH_H +#define HW_MISC_LATCHING_SWITCH_H + +#include "qom/object.h" +#include "hw/qdev-core.h" + +#define TYPE_LATCHING_SWITCH "latching-switch" + +enum TriggerEdge { + TRIGGER_EDGE_FALLING, + TRIGGER_EDGE_RISING, + TRIGGER_EDGE_BOTH, +}; + +struct LatchingSwitchState { + /* Private */ + DeviceState parent_obj; + + /* Public */ + qemu_irq input; + qemu_irq output; + + /* Properties */ + bool state; + uint8_t trigger_edge; + char *description; +}; +typedef struct LatchingSwitchState LatchingSwitchState; +DECLARE_INSTANCE_CHECKER(LatchingSwitchState, LATCHING_SWITCH, + TYPE_LATCHING_SWITCH) + +/** + * latching_switch_create_simple: Create and realize a device + * @parentobj: the parent object + * @state: the initial state of the switch + * @trigger_edge: the trigger edge of the switch + * 0: falling edge + * 1: rising edge + * 2: both edge + * + * Create the device state structure, initialize it, and + * drop the reference to it (the device is realized). + * + */ +LatchingSwitchState *latching_switch_create_simple(Object *parentobj, + bool state, + uint8_t trigger_edge); + +#endif /* HW_MISC_LATCHING_SWITCH_H */ --=20 2.25.1 From nobody Fri Apr 19 02:05:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1663713795; cv=none; d=zohomail.com; s=zohoarc; b=NwtpLO/dxN7NAZU6BZnx6RLHaCjSpMRzz0G9Ndc3H7Ybrb+o/Z0oewU/Er11ZYM0Ucs8Q70RJ7aNWy/NBanE0hI4gWqAkFBglgMWOOvJtf2rH9Z5P+Cuq95D6zLRLtSn3dB9pwTh+rYt5qC+qXXDp+v0pzOV9na1oanAqL83nYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663713795; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qlTkrqVb2aMkLpsUHrMoW58Kky3kHTKxI6M8gj2V1zA=; b=liZ9PoTPvuozoTCpaYTMp5Ufmjg5w742FRgoUfpbvH3PIVadKVQH+3fWjz+409b+AOzE9lx7jPBHoRRsLp0JB9uliQ/5u7Nidm2wnAdCgod+5BY6aHyXQv+HKabB6b5/YH0RQjHVms++WIpXE56J/HrcH5Y6aQRQsi23YWxe4us= 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=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1663713795120971.209842666012; Tue, 20 Sep 2022 15:43:15 -0700 (PDT) Received: from localhost ([::1]:49966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oalxR-0000Z4-VR for importer@patchew.org; Tue, 20 Sep 2022 18:43:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56700) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oaiGY-0004RU-4W for qemu-devel@nongnu.org; Tue, 20 Sep 2022 14:46:51 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:45767) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oaiGU-0007Qt-E6 for qemu-devel@nongnu.org; Tue, 20 Sep 2022 14:46:41 -0400 Received: by mail-pj1-x1031.google.com with SMTP id p1-20020a17090a2d8100b0020040a3f75eso3339146pjd.4 for ; Tue, 20 Sep 2022 11:46:38 -0700 (PDT) Received: from localhost ([49.7.199.230]) by smtp.gmail.com with ESMTPSA id x2-20020a17090a1f8200b0020379616053sm203667pja.57.2022.09.20.11.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 11:46:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=qlTkrqVb2aMkLpsUHrMoW58Kky3kHTKxI6M8gj2V1zA=; b=LBX0XO9yQRjLND9QEAKvEB6zfPznF3dsCCHx05wtFKbOHtyRAGkUoHkJ39fzvKD6kk 9sVfDrfFDqNou/tLpdBJC3QUilSBtr0FQbYbiTbqrHLXuCa9J2+YdrTjn57PWyxJJEJT hGcy8qTMQhysnCc8MEdu49uLbR96Meuwa7VjA6qqPHrx5QNlcFSEMFZbLsEykXdqTHiu Lw1/qawKpNjjaLljYJ56RK171qgdvFhwfr3MPNCZE0Aeclh95TVv0Y1+DcfILr9BuH6N cfmszz7PiD+sbSlwJazt/ObeKpAmmsRrsft68cT57/eGGpD6ZtyRelgtDiaeorY3rI/j UnSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=qlTkrqVb2aMkLpsUHrMoW58Kky3kHTKxI6M8gj2V1zA=; b=mPiEdr0MBTdXt1Ub1t0eJ5UZrtFYGiJVHE8NpdZn5Kz5ytb8Txs26zht2zgc4ToCDl CBTkVg/cagh39lepEjrpK+TvYMlz3mYFtTQHkKOzZVfCNXk8f4z0r8UpFvjrEF1Tg0Sx yNjo8u2qQkstOeOT1t+pdPyWIx019rui3fXCFBD6cVVq1JKO71XFm5SWRYkvP7nk0Kl/ yl5WPq5seQ5q2N5NQ5i5yIMNWoZA+tnsE0+xSy7VAIpPG2N1iQG8K0qKPw6fNKyl2r3x 6F7gIV9Kr8r9RcTDSl5yZnkYj4Fp8xxI1pWtSQa23/uhGLOxBXwQOtjqCVEHlmU6SGc5 dHdQ== X-Gm-Message-State: ACrzQf2mepfoW4osbyBEERVhcpzSO5WhJyKUiPHezNfCxuozLR2s6oIA 9MslZzTOxpOMPVJMpmaENv/IAg== X-Google-Smtp-Source: AMsMyM55kfMcocVonbj2msJBNmbeXWteVDWaf9trrIo5VUCyBUJrE4vSt6OrG77dD7XkQK0fqdhYwg== X-Received: by 2002:a17:902:e5cd:b0:176:ad01:ab47 with SMTP id u13-20020a170902e5cd00b00176ad01ab47mr958363plf.133.1663699596882; Tue, 20 Sep 2022 11:46:36 -0700 (PDT) From: Jian Zhang To: f4bug@amsat.org, peter.maydell@linaro.org, clg@kaod.org, andrew@aj.id.au, joel@jms.id.au, qemu-devel@nongnu.org, qemu-arm@nongnu.org Cc: yulei.sh@bytedance.com, tangyiwei.2022@bytedance.com, chentingting.2150@bytedance.com, yuhao.17@bytedance.com, wangxiaohua.1217@bytedance.com, xiening.xll@bytedance.com Subject: [PATCH v2 2/3] hw/gpio/aspeed_gpio: Add gpios in/out init Date: Wed, 21 Sep 2022 02:46:18 +0800 Message-Id: <20220920184619.3370115-3-zhangjian.3032@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220920184619.3370115-1-zhangjian.3032@bytedance.com> References: <20220920184619.3370115-1-zhangjian.3032@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=zhangjian.3032@bytedance.com; helo=mail-pj1-x1031.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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" X-ZohoMail-DKIM: pass (identity @bytedance-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1663713797270100001 Content-Type: text/plain; charset="utf-8" Add gpios in/out init for aspeed gpio to add the ability to connect to other gpio devices. Based the qdev-core.h comments, If you want to connect a GPIO to other devices, you need to call qdev_init_gpio_in() or qdev_init_gpio_out(). ``` For input gpios: * * Outbound GPIO lines can be connected to any qemu_irq, but the common * case is connecting them to another device's inbound GPIO line, using * the qemu_irq returned by qdev_get_gpio_in() or qdev_get_gpio_in_named(). For output gpios: * This function is intended to be used by board code or SoC "container" * device models to wire up the GPIO lines; usually the return value * will be passed to qdev_connect_gpio_out() or a similar function to * connect another device's output GPIO line to this input. ``` Signed-off-by: Jian Zhang --- hw/gpio/aspeed_gpio.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hw/gpio/aspeed_gpio.c b/hw/gpio/aspeed_gpio.c index 1e267dd482..51f5f1c386 100644 --- a/hw/gpio/aspeed_gpio.c +++ b/hw/gpio/aspeed_gpio.c @@ -1013,6 +1013,17 @@ static void aspeed_gpio_reset(DeviceState *dev) memset(s->sets, 0, sizeof(s->sets)); } =20 +static void aspeed_gpio_set(void *opaque, int line, int new_state) +{ + AspeedGPIOState *s =3D ASPEED_GPIO(opaque); + uint32_t set_idx, pin; + + set_idx =3D line / ASPEED_GPIOS_PER_SET; + pin =3D line % ASPEED_GPIOS_PER_SET; + + aspeed_gpio_set_pin_level(s, set_idx, pin, new_state); +} + static void aspeed_gpio_realize(DeviceState *dev, Error **errp) { AspeedGPIOState *s =3D ASPEED_GPIO(dev); @@ -1037,6 +1048,12 @@ static void aspeed_gpio_realize(DeviceState *dev, Er= ror **errp) memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_gpio_ops, s, TYPE_ASPEED_GPIO, 0x800); =20 + /* TODO: Maybe could in named, not anonymous is better */ + qdev_init_gpio_out(dev, &s->gpios[0][0], + ASPEED_GPIO_MAX_NR_SETS * ASPEED_GPIOS_PER_SET); + qdev_init_gpio_in(dev, aspeed_gpio_set, + ASPEED_GPIO_MAX_NR_SETS * ASPEED_GPIOS_PER_SET); + sysbus_init_mmio(sbd, &s->iomem); } =20 --=20 2.25.1 From nobody Fri Apr 19 02:05:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1663714011; cv=none; d=zohomail.com; s=zohoarc; b=a1N2YgOKQkfAyLjaokBdJR2DeDuFzlT5jMl6bhXtSoWssSyK+iqcP0arf6V18KxM6qG1TY31dX6oBSztk5vFwNS/RZmZOI0nGlDC3rVFo9msm5Y5wHqLz4ML31hEtTfDPEgdJ8HQpaBr1xkBJFTjDk1pzRQIbR1RxAJ1TW0qr18= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663714011; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3k7De6dda7HtE0VoeJmLCIiYC0o1UACU10YlAWqrISw=; b=cy0KT6E4Fkvf590+nLQkvSG118WIdawYdyjaEV5C7OmtnWyw2ynB/3AQWEa1D1/vJ7BSijsCW5gd0GlllL9rD8t8k0xbnguP+mDHDcboh6/PhoPVNfUEpKXAaZpF3R89YUDvO+l8YWncSaypnuJP9X+KG+U1EQcz206YfsrX+zM= 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=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1663714011863619.9767642946057; Tue, 20 Sep 2022 15:46:51 -0700 (PDT) Received: from localhost ([::1]:34284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oam0w-0006z5-JY for importer@patchew.org; Tue, 20 Sep 2022 18:46:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oaiGe-0004Ru-F7 for qemu-devel@nongnu.org; Tue, 20 Sep 2022 14:46:51 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:35524) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oaiGZ-0007S3-Vx for qemu-devel@nongnu.org; Tue, 20 Sep 2022 14:46:46 -0400 Received: by mail-pf1-x42c.google.com with SMTP id e5so3598685pfl.2 for ; Tue, 20 Sep 2022 11:46:43 -0700 (PDT) Received: from localhost ([49.7.199.220]) by smtp.gmail.com with ESMTPSA id y16-20020a626410000000b00545f5046372sm206927pfb.208.2022.09.20.11.46.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 11:46:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=3k7De6dda7HtE0VoeJmLCIiYC0o1UACU10YlAWqrISw=; b=uysbs+EUwH5Rc9qwEQ7m40LbRGRcauWexufWDZqaffyGfLYBIi8zSyFKka7GcmyM4B 8gvQVnsc9t9IdIjnVHW4Wyjj73QdojRw88HYvfY3qPdka7b8gGeQQd/X6dgZcpbtOkq/ 8RFO4o/rFeev2ghfuQ9yk0E81FvTa84E/WuCUCIKNBs8KqNwVpF3i4eU9wz5eXmA7arX s64JeodAFk7oSv5Ae+8vyiPCO7ZZJlBzOn+DBCBGnLP5f3jYWaJqx+ZQRlctYftEl/yk ce16MY3ocBJHxFoy1r/dDgv8IBVcXP/WX5wePI/TseKBkFh0imlwE9rDrc4lTv8MnLDC AGyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=3k7De6dda7HtE0VoeJmLCIiYC0o1UACU10YlAWqrISw=; b=JVOwgoejFQ/jp808tv+AYqkuQV3YUZV1T0Z2s2/SYM5TzRTxwlq0Z/jC6y+lyK53hJ TcaIGK5sCBhR8C4JKPQ+udSqWDBeb61qiIWhKQCc+R0SavjZOSgGDuR9LQAASRVmo1nt db+2jiBlXRuiNHevvpo+LVV+xG0C2QCUeGtXW+OkXqvz4BNTcd6vpJDvblpU08lQXtDM aqofQvSgkG2HCkdvjpsDaN7AX37YRKQ3iaX4TNvA2V72XEfk9htik5dkSCFqD/zVo4Tf +Na/Xpp7xxMI4s9LKXTH9HjzgdPRksVAex5Q01PTIG5kPlDAt6CXPRx0uC7CT3AzKPsh K4Ng== X-Gm-Message-State: ACrzQf3Edn8Z3NWnSSJoX2POpR70kNKEhhjCgAzZFuF8jKLUDcHVijEU /g+3JV83pnuanFREHfEocM5yJw== X-Google-Smtp-Source: AMsMyM6AlbLZXygYBJuDmI11ITTNUzqsA+ZTgNE1zBYM0CsZG2+nXKnlcHzrUPzk+EiVC1NaPmWhQg== X-Received: by 2002:a05:6a00:15c9:b0:541:1767:4ce2 with SMTP id o9-20020a056a0015c900b0054117674ce2mr24202493pfu.30.1663699602291; Tue, 20 Sep 2022 11:46:42 -0700 (PDT) From: Jian Zhang To: f4bug@amsat.org, peter.maydell@linaro.org, clg@kaod.org, andrew@aj.id.au, joel@jms.id.au, qemu-devel@nongnu.org, qemu-arm@nongnu.org Cc: yulei.sh@bytedance.com, tangyiwei.2022@bytedance.com, chentingting.2150@bytedance.com, yuhao.17@bytedance.com, wangxiaohua.1217@bytedance.com, xiening.xll@bytedance.com Subject: [PATCH v2 3/3] hw/arm/aspeed: g220a: Add a latching switch device Date: Wed, 21 Sep 2022 02:46:19 +0800 Message-Id: <20220920184619.3370115-4-zhangjian.3032@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220920184619.3370115-1-zhangjian.3032@bytedance.com> References: <20220920184619.3370115-1-zhangjian.3032@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=zhangjian.3032@bytedance.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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" X-ZohoMail-DKIM: pass (identity @bytedance-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1663714014232100001 Content-Type: text/plain; charset="utf-8" Add a latching switch device connect between g220a BMC machind(soc gpio) as host-power. The latching switch device default state is off and trigger edge is falling edge. Tested: In qemu, use g220a image ~# ipmitool power status Chassis Power is off ~# ipmitool power on Chassis Power Control: Up/On ~# ipmitool power status Chassis Power is on ~# ipmitool power off Chassis Power Control: Down/Off ~# ipmitool power status Chassis Power is off Signed-off-by: Jian Zhang --- hw/arm/Kconfig | 1 + hw/arm/aspeed.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 15fa79afd3..f2455db5a0 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -457,6 +457,7 @@ config ASPEED_SOC select LED select PMBUS select MAX31785 + select LATCHING_SWITCH =20 config MPS2 bool diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c index bc3ecdb619..070de3aeff 100644 --- a/hw/arm/aspeed.c +++ b/hw/arm/aspeed.c @@ -27,6 +27,7 @@ #include "qemu/units.h" #include "hw/qdev-clock.h" #include "sysemu/sysemu.h" +#include "hw/misc/latching_switch.h" =20 static struct arm_boot_info aspeed_board_binfo =3D { .board_id =3D -1, /* device-tree-only board */ @@ -666,6 +667,25 @@ static void g220a_bmc_i2c_init(AspeedMachineState *bmc) }; smbus_eeprom_init_one(aspeed_i2c_get_bus(&soc->i2c, 4), 0x57, eeprom_buf); + + /* Add a host-power device */ + LatchingSwitchState *power =3D + latching_switch_create_simple(OBJECT(bmc), + false, TRIGGER_EDGE_FALLING); + + /* + * connect the input to soc(out, power button) + * the power button in g220a is 215 + */ + qdev_connect_gpio_out(DEVICE(&bmc->soc.gpio), 215, + qdev_get_gpio_in(DEVICE(power), 0)); + + /* + * connect the output to soc(in, power good signal) + * the power good in g220a is 209 + */ + qdev_connect_gpio_out(DEVICE(power), 0, + qdev_get_gpio_in(DEVICE(&bmc->soc.gpio), 209)); } =20 static void aspeed_eeprom_init(I2CBus *bus, uint8_t addr, uint32_t rsize) --=20 2.25.1