From nobody Mon Nov 17 09:50:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.208.67 as permitted sender) client-ip=209.85.208.67; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ed1-f67.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.208.67 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=fail(p=none dis=none) header.from=amsat.org ARC-Seal: i=1; a=rsa-sha256; t=1603749995; cv=none; d=zohomail.com; s=zohoarc; b=OVJqrh4pFyFOi09p9imWi6mcNn+ldCXwbCj+ZKvReKDthrmllr4QficuRAVggAgX0EQMhVQBOZlaBREI07BwdbFHOV6nEuxRkRw2CDB4ZQ5dq9NPQkVCvNwVV0yFRIaZyybq5icDzRyMJd65OI3B2GwBs1UIPdY8U1qVNoVdfdk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603749995; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rp+PT0DKslfkK4k99N9IovK0uPHrIUK2nuMArbsAM+E=; b=A+kjWf/8pbxXfxOdLuPXXFL/53bdLVXFpTPS6ausJ+mEJyOJpECiHgdcx58GHxoQlckFSg6edlpeAg1jZKEda8eUAkP+ZczMJMz4liw2l0U5YKNuSLrSbSKj55/TbuRCL9V77eKycOPLeTVGtZlWQyJEv0+ROPHKOtPjg9Aiz+g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.208.67 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) by mx.zohomail.com with SMTPS id 1603749995293494.223804821144; Mon, 26 Oct 2020 15:06:35 -0700 (PDT) Received: by mail-ed1-f67.google.com with SMTP id bc23so11283877edb.5 for ; Mon, 26 Oct 2020 15:06:34 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (237.red-88-18-140.staticip.rima-tde.net. [88.18.140.237]) by smtp.gmail.com with ESMTPSA id ao17sm6696333ejc.18.2020.10.26.15.06.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 15:06:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rp+PT0DKslfkK4k99N9IovK0uPHrIUK2nuMArbsAM+E=; b=qz1tu9XjbMz5jQTmKqvIerLy11A/omROPUfKyVmtCtuVCvcAy8x7yVO85WvocIrNx+ /128MWnsyb5SHxtGV5T5Zgkaaadwoq+W0RYmCiiL6AzrYQpOI+vvYR4h4Q1wyH5540l5 t0dwyFYZVJr5l5w3Ggy11bmVF7ju7tEYc/oHtH0LhTVwS0SNqXxLEDWBgd3txj9zhyBP noYz9WrW2QvocPuyNimbpMpkE0E09CaNrU5iQfuoeU0RY/bNfny9HoH8TcukeH5y7lX7 G/ZEljfnvtjMpXp9xWXffGY+xXaX/u4eLZav+925RX5aRMfEVGWtPra6Qksx6b0AdL4h 63Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=rp+PT0DKslfkK4k99N9IovK0uPHrIUK2nuMArbsAM+E=; b=DQAI66irFnuE5jEJnTALM+5B/EOE+R6IddaJWTBU8k3kPfOEhIZ4RB4IUQ5VCUqz6O kwQSRFIM37bM3YZNFkb354F6rT7LoBHGeI60RBRdLusKJhWsZIue3bXq+n8T3eHcePtB l+wpixrU8GFqq3ZuXKpSzckUkoEO6hOSJsdBg/7dxGCosjz79PsUQakA5i4VdQKJdzVC vdHk/VzGCn0nYH07m+hxwNCaHmYpIxRR9tASkMCiLjn0tyXXAXUbyRD+CU7iERZfEaXo Eyc7GoHDYfEgTDfusqxws5KLVxv9QUlzflqMK2IEPqrVyOXYeHCiFLd2J+U8wwXEsYeV pvFQ== X-Gm-Message-State: AOAM530gv5PJai5VprQuzjaIjxhcENjSPUKd4FIxKvY/ngEZKRGGam7i ZZ/xHtMcCRKqPWNd00+qVHg= X-Google-Smtp-Source: ABdhPJyFYECewczaZ6w3tXITbgzxryHLD/LrkanichJCdHInM0QSjuG4Z5mGp6ChlcZGffnv4yWX5Q== X-Received: by 2002:a05:6402:143d:: with SMTP id c29mr12995229edx.277.1603749993173; Mon, 26 Oct 2020 15:06:33 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Andrew Jeffery , Joel Stanley , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Andrzej Zaborowski , qemu-arm@nongnu.org, Paolo Bonzini , Peter Maydell , Luc Michel , Richard Henderson Subject: [PULL 1/7] hw/misc/led: Add a LED device Date: Mon, 26 Oct 2020 23:06:18 +0100 Message-Id: <20201026220624.60878-2-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026220624.60878-1-f4bug@amsat.org> References: <20201026220624.60878-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) Add a LED device which can be connected to a GPIO output. They can also be dimmed with PWM devices. For now we do not implement the dimmed mode, but in preparation of a future implementation, we start using the LED intensity. LEDs are limited to a fixed set of colors. Reviewed-by: Luc Michel Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20200912134041.946260-2-f4bug@amsat.org> --- include/hw/misc/led.h | 87 ++++++++++++++++++++++++++ hw/misc/led.c | 142 ++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 6 ++ hw/misc/Kconfig | 3 + hw/misc/meson.build | 1 + hw/misc/trace-events | 3 + 6 files changed, 242 insertions(+) create mode 100644 include/hw/misc/led.h create mode 100644 hw/misc/led.c diff --git a/include/hw/misc/led.h b/include/hw/misc/led.h new file mode 100644 index 00000000000..286d37c75c1 --- /dev/null +++ b/include/hw/misc/led.h @@ -0,0 +1,87 @@ +/* + * QEMU single LED device + * + * Copyright (C) 2020 Philippe Mathieu-Daud=C3=A9 + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef HW_MISC_LED_H +#define HW_MISC_LED_H + +#include "qom/object.h" + +#define TYPE_LED "led" + +/** + * LEDColor: Color of a LED + * + * This set is restricted to physically available LED colors. + * + * LED colors from 'Table 1. Product performance of LUXEON Rebel Color + * Line' of the 'DS68 LUXEON Rebel Color Line' datasheet available at: + * https://www.lumileds.com/products/color-leds/luxeon-rebel-color/ + */ +typedef enum { /* Coarse wavelength range */ + LED_COLOR_VIOLET, /* 425 nm */ + LED_COLOR_BLUE, /* 475 nm */ + LED_COLOR_CYAN, /* 500 nm */ + LED_COLOR_GREEN, /* 535 nm */ + LED_COLOR_AMBER, /* 590 nm */ + LED_COLOR_ORANGE, /* 615 nm */ + LED_COLOR_RED, /* 630 nm */ +} LEDColor; + +struct LEDState { + /* Private */ + DeviceState parent_obj; + /* Public */ + + uint8_t intensity_percent; + + /* Properties */ + char *description; + char *color; +}; +typedef struct LEDState LEDState; +DECLARE_INSTANCE_CHECKER(LEDState, LED, TYPE_LED) + +/** + * led_set_intensity: Set the intensity of a LED device + * @s: the LED object + * @intensity_percent: intensity as percentage in range 0 to 100. + */ +void led_set_intensity(LEDState *s, unsigned intensity_percent); + +/** + * led_get_intensity: + * @s: the LED object + * + * Returns: The LED intensity as percentage in range 0 to 100. + */ +unsigned led_get_intensity(LEDState *s); + +/** + * led_set_state: Set the state of a LED device + * @s: the LED object + * @is_emitting: boolean indicating whether the LED is emitting + * + * This utility is meant for LED connected to GPIO. + */ +void led_set_state(LEDState *s, bool is_emitting); + +/** + * led_create_simple: Create and realize a LED device + * @parentobj: the parent object + * @color: color of the LED + * @description: description of the LED (optional) + * + * Create the device state structure, initialize it, and + * drop the reference to it (the device is realized). + * + * Returns: The newly allocated and instantiated LED object. + */ +LEDState *led_create_simple(Object *parentobj, + LEDColor color, + const char *description); + +#endif /* HW_MISC_LED_H */ diff --git a/hw/misc/led.c b/hw/misc/led.c new file mode 100644 index 00000000000..1e2f49c5710 --- /dev/null +++ b/hw/misc/led.c @@ -0,0 +1,142 @@ +/* + * QEMU single LED device + * + * Copyright (C) 2020 Philippe Mathieu-Daud=C3=A9 + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "migration/vmstate.h" +#include "hw/qdev-properties.h" +#include "hw/misc/led.h" +#include "trace.h" + +#define LED_INTENSITY_PERCENT_MAX 100 + +static const char * const led_color_name[] =3D { + [LED_COLOR_VIOLET] =3D "violet", + [LED_COLOR_BLUE] =3D "blue", + [LED_COLOR_CYAN] =3D "cyan", + [LED_COLOR_GREEN] =3D "green", + [LED_COLOR_AMBER] =3D "amber", + [LED_COLOR_ORANGE] =3D "orange", + [LED_COLOR_RED] =3D "red", +}; + +static bool led_color_name_is_valid(const char *color_name) +{ + for (size_t i =3D 0; i < ARRAY_SIZE(led_color_name); i++) { + if (strcmp(color_name, led_color_name[i]) =3D=3D 0) { + return true; + } + } + return false; +} + +void led_set_intensity(LEDState *s, unsigned intensity_percent) +{ + if (intensity_percent > LED_INTENSITY_PERCENT_MAX) { + intensity_percent =3D LED_INTENSITY_PERCENT_MAX; + } + trace_led_set_intensity(s->description, s->color, intensity_percent); + s->intensity_percent =3D intensity_percent; +} + +unsigned led_get_intensity(LEDState *s) +{ + return s->intensity_percent; +} + +void led_set_state(LEDState *s, bool is_emitting) +{ + led_set_intensity(s, is_emitting ? LED_INTENSITY_PERCENT_MAX : 0); +} + +static void led_reset(DeviceState *dev) +{ + LEDState *s =3D LED(dev); + + led_set_state(s, false); +} + +static const VMStateDescription vmstate_led =3D { + .name =3D TYPE_LED, + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_UINT8(intensity_percent, LEDState), + VMSTATE_END_OF_LIST() + } +}; + +static void led_realize(DeviceState *dev, Error **errp) +{ + LEDState *s =3D LED(dev); + + if (s->color =3D=3D NULL) { + error_setg(errp, "property 'color' not specified"); + return; + } else if (!led_color_name_is_valid(s->color)) { + error_setg(errp, "property 'color' invalid or not supported"); + return; + } + if (s->description =3D=3D NULL) { + s->description =3D g_strdup("n/a"); + } +} + +static Property led_properties[] =3D { + DEFINE_PROP_STRING("color", LEDState, color), + DEFINE_PROP_STRING("description", LEDState, description), + DEFINE_PROP_END_OF_LIST(), +}; + +static void led_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->desc =3D "LED"; + dc->vmsd =3D &vmstate_led; + dc->reset =3D led_reset; + dc->realize =3D led_realize; + set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); + device_class_set_props(dc, led_properties); +} + +static const TypeInfo led_info =3D { + .name =3D TYPE_LED, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(LEDState), + .class_init =3D led_class_init +}; + +static void led_register_types(void) +{ + type_register_static(&led_info); +} + +type_init(led_register_types) + +LEDState *led_create_simple(Object *parentobj, + LEDColor color, + const char *description) +{ + g_autofree char *name =3D NULL; + DeviceState *dev; + + dev =3D qdev_new(TYPE_LED); + qdev_prop_set_string(dev, "color", led_color_name[color]); + if (!description) { + static unsigned undescribed_led_id; + name =3D g_strdup_printf("undescribed-led-#%u", undescribed_led_id= ++); + } else { + qdev_prop_set_string(dev, "description", description); + name =3D g_ascii_strdown(description, -1); + name =3D g_strdelimit(name, " #", '-'); + } + object_property_add_child(parentobj, name, OBJECT(dev)); + qdev_realize_and_unref(dev, NULL, &error_fatal); + + return LED(dev); +} diff --git a/MAINTAINERS b/MAINTAINERS index ef6f5c73998..7e442b52472 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1967,6 +1967,12 @@ F: docs/specs/vmgenid.txt F: tests/qtest/vmgenid-test.c F: stubs/vmgenid.c =20 +LED +M: Philippe Mathieu-Daud=C3=A9 +S: Maintained +F: include/hw/misc/led.h +F: hw/misc/led.c + Unimplemented device M: Peter Maydell R: Philippe Mathieu-Daud=C3=A9 diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig index 31854561105..e4d059591ad 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -126,6 +126,9 @@ config AUX config UNIMP bool =20 +config LED + bool + config MAC_VIA bool select MOS6522 diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 793d45b1dc4..aa8ec3bca9b 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -11,6 +11,7 @@ softmmu_ss.add(when: 'CONFIG_TMP421', if_true: files('tmp421.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')) =20 # ARM devices softmmu_ss.add(when: 'CONFIG_PL310', if_true: files('arm_l2x0.c')) diff --git a/hw/misc/trace-events b/hw/misc/trace-events index 6054f9adf35..2b6310dbe4b 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -223,6 +223,9 @@ via1_adb_poll(uint8_t data, const char *vadbint, int st= atus, int index, int size grlib_ahb_pnp_read(uint64_t addr, uint32_t value) "AHB PnP read addr:0x%03= "PRIx64" data:0x%08x" grlib_apb_pnp_read(uint64_t addr, uint32_t value) "APB PnP read addr:0x%03= "PRIx64" data:0x%08x" =20 +# led.c +led_set_intensity(const char *color, const char *desc, uint8_t intensity_p= ercent) "LED desc:'%s' color:%s intensity: %u%%" + # pca9552.c pca955x_gpio_status(const char *description, const char *buf) "%s GPIOs 0-= 15 [%s]" pca955x_gpio_change(const char *description, unsigned id, unsigned prev_st= ate, unsigned current_state) "%s GPIO id:%u status: %u -> %u" --=20 2.26.2 From nobody Mon Nov 17 09:50:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.208.44 as permitted sender) client-ip=209.85.208.44; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ed1-f44.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.208.44 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=fail(p=none dis=none) header.from=amsat.org ARC-Seal: i=1; a=rsa-sha256; t=1603750001; cv=none; d=zohomail.com; s=zohoarc; b=JfPmL2+TkrgD0rbCvvjH4JULvtTx386KrUia2DufIB7kiFufi6/aS5ULy74r+FeWZ8IKYN+iqaWB0WYVtZTyTRZ5I0ilsUCONscCo1GKlkCDQsIViHQ4pgIKWf4ZZjXngtjnRk/4GRubIRVwBvW8plWJ2zEPbfaVaO8BL4DJhPw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603750001; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dMuCpvg2jvs8wv2yJweoNJ0vPwlnnXLBSkbONBKjyck=; b=iTwYMuY2rth+dpo7HAk73XTHtz/9YfYf1ZuRMDN9evpB/jZunGtoGCXYS0+O+76CvrThNynDBqCmGjD30/v1HqXA+wG98zDuZIjB34dXuf+aXWZr7QKod4/vF+LGdbrM3dcGnZV1eBXENwm9leCXrt/5RSfFJzyBrTxdClybecA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.208.44 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) by mx.zohomail.com with SMTPS id 1603750001047689.8114972293464; Mon, 26 Oct 2020 15:06:41 -0700 (PDT) Received: by mail-ed1-f44.google.com with SMTP id bc23so11284173edb.5 for ; Mon, 26 Oct 2020 15:06:40 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (237.red-88-18-140.staticip.rima-tde.net. [88.18.140.237]) by smtp.gmail.com with ESMTPSA id ld2sm1287166ejb.94.2020.10.26.15.06.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 15:06:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dMuCpvg2jvs8wv2yJweoNJ0vPwlnnXLBSkbONBKjyck=; b=pe8NOjvIu85re1H6MPR7cdc2wMW0nE4BoXaIStxKCOtIxWGkSG4SzQE2nFNzLhe+/T IQ3qLhF5dKDYpWcXN7w3OrqBJsj0cPdHpUejFeo2yYgYLr/Jgb9NfAoFcdhakJ+/wFNm DwKdEhA2IVoRZtvOhp/SENUmj97S+EyFJJW1Za7zF94QO+qavku0dB9xkvQK+6zDvpf8 NOELvlcwA6tbzohmrhq+wIDYCxvlXmiCqqDYrllklV3AmodWRGB/jpZwrBMerQT/rbeu dImPwz22RIqpq/3B4YEmjxMT99YasItIvrmT+Yn08p8lRHIohGcA6nmvFu8Mx3/vpyK4 r4rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=dMuCpvg2jvs8wv2yJweoNJ0vPwlnnXLBSkbONBKjyck=; b=HFcZJPPKPUFH6L0IJBhmNpW8pnQpBL+qw9Y633hWHf2om6QLacHuvoHhfEmrMxLY9F SkUQwZauGW3G1fUZB4A/nEGVohFiy0BT/6KyypOnv/6mN1qMc8dg8hIYIAeQXXnQRpcp 1jo9snJC4Fn2aiyyuT27P4ikIQKdQ5zX9HDk8FItjPtBHpCBiPJlfgTBJ1hTiKpFzuLz OLBQNJIsn4gOqWlvPCutS69O/nxOW7DBjN3399534X8uJn+jhzurNv4I8LJe9nWHTgDV hrnIFtkXyx79wlBkJqk7z+K1QOPrYw7Qs33RpdVIhRT+Id+NFn8gMDmBWz+/nPj9+kPo g+Kg== X-Gm-Message-State: AOAM530iGcF1onIl8Tp6EC0T2Ly1vNo/ByG93g39EDETbqXF8+At7PhG IEHW9Iw2G/GRXCYvOO/VgrY= X-Google-Smtp-Source: ABdhPJz1PqOnu3wNrP++2R0bWoY3NBBwfni/CvOyxaZZ8CSzGWD6P+Rj7Wkv3ZueE6dHJr4SFuA+TA== X-Received: by 2002:aa7:cd14:: with SMTP id b20mr17950877edw.366.1603749999128; Mon, 26 Oct 2020 15:06:39 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Andrew Jeffery , Joel Stanley , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Andrzej Zaborowski , qemu-arm@nongnu.org, Paolo Bonzini , Peter Maydell , Richard Henderson , Luc Michel Subject: [PULL 2/7] hw/misc/led: Allow connecting from GPIO output Date: Mon, 26 Oct 2020 23:06:19 +0100 Message-Id: <20201026220624.60878-3-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026220624.60878-1-f4bug@amsat.org> References: <20201026220624.60878-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) Some devices expose GPIO lines. Add a GPIO qdev input to our LED device, so we can connect a GPIO output using qdev_connect_gpio_out(). When used with GPIOs, the intensity can only be either minium or maximum. This depends of the polarity of the GPIO (which can be inverted). Declare the GpioPolarity type to model the polarity. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Reviewed-by: Luc Michel Message-Id: <20200912134041.946260-3-f4bug@amsat.org> --- include/hw/misc/led.h | 10 ++++++++++ include/hw/qdev-core.h | 16 ++++++++++++++++ hw/misc/led.c | 17 ++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/include/hw/misc/led.h b/include/hw/misc/led.h index 286d37c75c1..aa359b87c20 100644 --- a/include/hw/misc/led.h +++ b/include/hw/misc/led.h @@ -9,6 +9,7 @@ #define HW_MISC_LED_H =20 #include "qom/object.h" +#include "hw/qdev-core.h" =20 #define TYPE_LED "led" =20 @@ -37,10 +38,17 @@ struct LEDState { /* Public */ =20 uint8_t intensity_percent; + qemu_irq irq; =20 /* Properties */ char *description; char *color; + /* + * Determines whether a GPIO is using a positive (active-high) + * logic (when used with GPIO, the intensity at reset is related + * to the GPIO polarity). + */ + bool gpio_active_high; }; typedef struct LEDState LEDState; DECLARE_INSTANCE_CHECKER(LEDState, LED, TYPE_LED) @@ -72,6 +80,7 @@ void led_set_state(LEDState *s, bool is_emitting); /** * led_create_simple: Create and realize a LED device * @parentobj: the parent object + * @gpio_polarity: GPIO polarity * @color: color of the LED * @description: description of the LED (optional) * @@ -81,6 +90,7 @@ void led_set_state(LEDState *s, bool is_emitting); * Returns: The newly allocated and instantiated LED object. */ LEDState *led_create_simple(Object *parentobj, + GpioPolarity gpio_polarity, LEDColor color, const char *description); =20 diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 868973319ee..a653295d6fc 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -443,6 +443,22 @@ void qdev_simple_device_unplug_cb(HotplugHandler *hotp= lug_dev, void qdev_machine_creation_done(void); bool qdev_machine_modified(void); =20 +/** + * GpioPolarity: Polarity of a GPIO line + * + * GPIO lines use either positive (active-high) logic, + * or negative (active-low) logic. + * + * In active-high logic (%GPIO_POLARITY_ACTIVE_HIGH), a pin is + * active when the voltage on the pin is high (relative to ground); + * whereas in active-low logic (%GPIO_POLARITY_ACTIVE_LOW), a pin + * is active when the voltage on the pin is low (or grounded). + */ +typedef enum { + GPIO_POLARITY_ACTIVE_LOW, + GPIO_POLARITY_ACTIVE_HIGH +} GpioPolarity; + /** * qdev_get_gpio_in: Get one of a device's anonymous input GPIO lines * @dev: Device whose GPIO we want diff --git a/hw/misc/led.c b/hw/misc/led.c index 1e2f49c5710..c5fa09a613a 100644 --- a/hw/misc/led.c +++ b/hw/misc/led.c @@ -10,6 +10,7 @@ #include "migration/vmstate.h" #include "hw/qdev-properties.h" #include "hw/misc/led.h" +#include "hw/irq.h" #include "trace.h" =20 #define LED_INTENSITY_PERCENT_MAX 100 @@ -53,11 +54,19 @@ void led_set_state(LEDState *s, bool is_emitting) led_set_intensity(s, is_emitting ? LED_INTENSITY_PERCENT_MAX : 0); } =20 +static void led_set_state_gpio_handler(void *opaque, int line, int new_sta= te) +{ + LEDState *s =3D LED(opaque); + + assert(line =3D=3D 0); + led_set_state(s, !!new_state !=3D s->gpio_active_high); +} + static void led_reset(DeviceState *dev) { LEDState *s =3D LED(dev); =20 - led_set_state(s, false); + led_set_state(s, s->gpio_active_high); } =20 static const VMStateDescription vmstate_led =3D { @@ -84,11 +93,14 @@ static void led_realize(DeviceState *dev, Error **errp) if (s->description =3D=3D NULL) { s->description =3D g_strdup("n/a"); } + + qdev_init_gpio_in(DEVICE(s), led_set_state_gpio_handler, 1); } =20 static Property led_properties[] =3D { DEFINE_PROP_STRING("color", LEDState, color), DEFINE_PROP_STRING("description", LEDState, description), + DEFINE_PROP_BOOL("gpio-active-high", LEDState, gpio_active_high, true), DEFINE_PROP_END_OF_LIST(), }; =20 @@ -119,6 +131,7 @@ static void led_register_types(void) type_init(led_register_types) =20 LEDState *led_create_simple(Object *parentobj, + GpioPolarity gpio_polarity, LEDColor color, const char *description) { @@ -126,6 +139,8 @@ LEDState *led_create_simple(Object *parentobj, DeviceState *dev; =20 dev =3D qdev_new(TYPE_LED); + qdev_prop_set_bit(dev, "gpio-active-high", + gpio_polarity =3D=3D GPIO_POLARITY_ACTIVE_HIGH); qdev_prop_set_string(dev, "color", led_color_name[color]); if (!description) { static unsigned undescribed_led_id; --=20 2.26.2 From nobody Mon Nov 17 09:50:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.218.54 as permitted sender) client-ip=209.85.218.54; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ej1-f54.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.218.54 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1603750007; cv=none; d=zohomail.com; s=zohoarc; b=dkTQ5ihe6u9gzJCzppYfi5nrI5qpIVOuid48CKVpKYtHv/flWLfR/SEKA/W+xKJucoUVy1t67psNVS5a+k5VPyw6Hm/FgIHQhOzwmG1YuU/Z/nfSajnww3ho9tqd5XobrhFfJgp36o1t8NNuFm4DUxDChPp90Ljw117T4PmxJd4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603750007; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5zqlhU2r4BQ3aIQwHO70lpJ2+WZUGh9Je97I/fi+pKw=; b=C3biIbsf1dV0M6cxsqCPqIKXVb4e4xdt9flRW68bphwEjS7G29mAzwW89/NoWT0wq40AM2Xo9HYWHnIAP2Ngimparm8IgnRRcrgxezbU2RjWhfkTCc7+f3M678ruEBNAF+YeRe/GnnsK3MELjg4FUikl/aaGgXdyWZnvMiYWda0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.218.54 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by mx.zohomail.com with SMTPS id 1603750007183198.8397774687088; Mon, 26 Oct 2020 15:06:47 -0700 (PDT) Received: by mail-ej1-f54.google.com with SMTP id t25so16032075ejd.13 for ; Mon, 26 Oct 2020 15:06:46 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (237.red-88-18-140.staticip.rima-tde.net. [88.18.140.237]) by smtp.gmail.com with ESMTPSA id z23sm6608971ejj.52.2020.10.26.15.06.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 15:06:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5zqlhU2r4BQ3aIQwHO70lpJ2+WZUGh9Je97I/fi+pKw=; b=Hn3wFgzhzNZbBQ7X74Bip28TTQsPDzSL3yXP5fIv2S+2E1ZELGXy0zVRoh7QNzAn5z B/pgTakNCEGG7m/EV+gtIDHsYG7Hcmbfdh9RKxiDeFIZQEmNUBnJiAZ3cpwrbs58tyx2 cZWnwOd2HdBODgKSYlsdxVJlq7aXJcwvmKCVSdkjku9s0nnFfrXDzcmww7KjZUxTkwy0 X/rHoXmCTNPgR0Pup6hjXuwg/H33wJmi3INoTecuzOCdVYEmDaSW8/BDBAeWqx/4JKvR ucLTQN99ERCooUXxcjXkvSVdKaujez5Q1Hyb6AMiuAq2cU7td5wKjzIDVq2hIA7lofjb HA9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=5zqlhU2r4BQ3aIQwHO70lpJ2+WZUGh9Je97I/fi+pKw=; b=PtGlu3zDyqNM1aNlDaVh6TR3LBbXyOibodgsaMrGmeZ7PVXLfhqSS/ALJ26nzSdsbP iq0oOwEcUM91PHHtNxnjsDAHemK1ZRVgQkiM+35SiLjMwRmBkkrRJ1ovBeJF+Yn25Wea fFuyfsPTnQCpJER/SddffjkJPQ7tCGmRMajFoTnxaHa51kL4gjg3be7apcQkoTMXRMu+ Ve4umy18x3nUAVTjfNdkgcOHPw21m2NOJ9x3xB4/ni2LdC3gqMVL27H3ZnGFL7JuY2bI wf45Z3282ZAGo/cl9BQXAzmmoI2++BqnBZ0ACi+Krbw81zahu2u/4tc3WqsAR/Ij1Afr 9l/g== X-Gm-Message-State: AOAM531EwQ9B8Ta4gg2eTzA7zr72+zFyVRzRl+bDG5jZzGEaDq6ZRLdK 4xVgZ/QTjd+2ppBUuJm/QAs= X-Google-Smtp-Source: ABdhPJxq+noztl/cIokYyuQcHL1f3dZ0hYcmpuOG3d5h163cM0b55EFg2pVRlXqZbHMYNck2kUNgdw== X-Received: by 2002:a17:906:c149:: with SMTP id dp9mr8509956ejc.88.1603750005200; Mon, 26 Oct 2020 15:06:45 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Andrew Jeffery , Joel Stanley , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Andrzej Zaborowski , qemu-arm@nongnu.org, Paolo Bonzini , Peter Maydell , Richard Henderson , Luc Michel Subject: [PULL 3/7] hw/misc/led: Emit a trace event when LED intensity has changed Date: Mon, 26 Oct 2020 23:06:20 +0100 Message-Id: <20201026220624.60878-4-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026220624.60878-1-f4bug@amsat.org> References: <20201026220624.60878-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) Track the LED intensity, and emit a trace event when it changes. Reviewed-by: Richard Henderson Reviewed-by: Luc Michel Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20200912134041.946260-4-f4bug@amsat.org> --- hw/misc/led.c | 4 ++++ hw/misc/trace-events | 1 + 2 files changed, 5 insertions(+) diff --git a/hw/misc/led.c b/hw/misc/led.c index c5fa09a613a..5266d026d0b 100644 --- a/hw/misc/led.c +++ b/hw/misc/led.c @@ -41,6 +41,10 @@ void led_set_intensity(LEDState *s, unsigned intensity_p= ercent) intensity_percent =3D LED_INTENSITY_PERCENT_MAX; } trace_led_set_intensity(s->description, s->color, intensity_percent); + if (intensity_percent !=3D s->intensity_percent) { + trace_led_change_intensity(s->description, s->color, + s->intensity_percent, intensity_percent= ); + } s->intensity_percent =3D intensity_percent; } =20 diff --git a/hw/misc/trace-events b/hw/misc/trace-events index 2b6310dbe4b..6bf7ce863fb 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -225,6 +225,7 @@ grlib_apb_pnp_read(uint64_t addr, uint32_t value) "APB = PnP read addr:0x%03"PRIx6 =20 # led.c led_set_intensity(const char *color, const char *desc, uint8_t intensity_p= ercent) "LED desc:'%s' color:%s intensity: %u%%" +led_change_intensity(const char *color, const char *desc, uint8_t old_inte= nsity_percent, uint8_t new_intensity_percent) "LED desc:'%s' color:%s inten= sity %u%% -> %u%%" =20 # pca9552.c pca955x_gpio_status(const char *description, const char *buf) "%s GPIOs 0-= 15 [%s]" --=20 2.26.2 From nobody Mon Nov 17 09:50:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.218.68 as permitted sender) client-ip=209.85.218.68; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ej1-f68.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.218.68 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1603750013; cv=none; d=zohomail.com; s=zohoarc; b=R/IaTFMR+W14DoA5Kv4DR6aZf7XEhHlkcFMYZsRN/GJudP0ULs9N54gPoSok9hp1JHWWA1GWW7Br6TYouCPNOym9mdoAusLoZwI1Ebzk44I06DRf+z8yQCjE2y1rxpF4GfGzjyu1hW19KcWxQNrKi4qt7a2soW62is/CSIPE/uE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603750013; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kkYx6ufxDsW7KHkPk9xI2ZT1n0haC2qnRwJcFZkWqPY=; b=l7cU+1x2jiZKOtWzfZqMHgMhbGJ4uip+1yoZaLheb02EtunvGpu5gKOfqOE8KTaEIx0Bll21Tr4YE/SwRhBGVwmgEvN5wX7kknX2+CW1eWSaPMCbcKtAkh9DoRlkq9S4LKiY46cKMD9QHUx/DSuNxeCwCPHdCeTlOU4zxplJVks= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.218.68 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-ej1-f68.google.com (mail-ej1-f68.google.com [209.85.218.68]) by mx.zohomail.com with SMTPS id 1603750013256370.765390833408; Mon, 26 Oct 2020 15:06:53 -0700 (PDT) Received: by mail-ej1-f68.google.com with SMTP id gs25so16127982ejb.1 for ; Mon, 26 Oct 2020 15:06:52 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (237.red-88-18-140.staticip.rima-tde.net. [88.18.140.237]) by smtp.gmail.com with ESMTPSA id j10sm6199584ejy.90.2020.10.26.15.06.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 15:06:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kkYx6ufxDsW7KHkPk9xI2ZT1n0haC2qnRwJcFZkWqPY=; b=oOUnqJjd44A9V0uVy6Bt58BV7gQ0P2/YTUfW4UFqJt54ddwi7McYw3p4YI4afVdT27 JO5gTfKrq/2YMXSgQdsbprS4GtGOqYX69dEQXavTjZx1m/h3VdT8qOrAKaYOp79auLVX cEetUdvPIORQLj+usr6K9iLPHLD3/ppaWBbNYnr9wUcQf86ZY7db7kZpFAPtH+wRtaUS 4X/HI6BtAs5HuvLlAbJIIA+9VMYr6BeBkUwONiHgq5frWExs6Dp+DiKKZ3SdBDiWmCrU SjGw/EuuZ5AmaAM7bWWUIYb5md3EUXRwQDl8/3tCb1Dd/aKRRZZJMuar7hf4Ri4CltFm 64ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=kkYx6ufxDsW7KHkPk9xI2ZT1n0haC2qnRwJcFZkWqPY=; b=azG5PuzY/tZkpv/1Xs0qQK/0Ey3uQsGO0AThrun9ZOxZZVjysEmMHhkPR94/F58Q09 Q/DFNgWwebkqWECotm0oKl9qZRsPz3ht4Wz4HH276FVcbM4B0lW3fiCAe4y4c5d4Sz6L r/bVoVIRNrrRMEOWnrG2vPFP8Wj5JsAliVUzgIcaf4LBrddLI0x+bs/XCP6ZsqJnlwXO rJ75Vz2naCXmZ9d356YQfWOn8pFtGdER1py2Gg0CP17il0RPhNeXRXyMrOQjjMs12W70 +nQrJrslseYi6wBNEIXRwcFYwK4wkwqra5yEdqJtTYcC9QixXktpGXXIoI5l4/fEYX+B IEPg== X-Gm-Message-State: AOAM530VGbFEkp8OBLGRlCg9+6t8fLnqj62n84CRS8UWu9J+458RbC2t JY929L3elRz2in6ojGmhIm4= X-Google-Smtp-Source: ABdhPJypqmunxv8fn8CVTBt1NixjQC4QefEdnZtkEL7NdqgxRlFZqmjp+ptIFyStyxHEJKAgpGJgSw== X-Received: by 2002:a17:907:43c0:: with SMTP id ok24mr17765576ejb.385.1603750011360; Mon, 26 Oct 2020 15:06:51 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Andrew Jeffery , Joel Stanley , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Andrzej Zaborowski , qemu-arm@nongnu.org, Paolo Bonzini , Peter Maydell , Richard Henderson , Luc Michel Subject: [PULL 4/7] hw/arm/aspeed: Add the 3 front LEDs drived by the PCA9552 #1 Date: Mon, 26 Oct 2020 23:06:21 +0100 Message-Id: <20201026220624.60878-5-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026220624.60878-1-f4bug@amsat.org> References: <20201026220624.60878-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) The Witherspoon has 3 LEDs connected to a PCA9552. Add them. The names and reset values are taken from: https://github.com/open-power/witherspoon-xml/blob/master/witherspoon.xml Example booting obmc-phosphor-image: $ qemu-system-arm -M witherspoon-bmc -trace led_change_intensity 1592693373.997015:led_change_intensity LED desc:'front-fault-4' color:gre= en intensity 0% -> 100% 1592693373.997632:led_change_intensity LED desc:'front-power-3' color:gre= en intensity 0% -> 100% 1592693373.998239:led_change_intensity LED desc:'front-id-5' color:green = intensity 0% -> 100% 1592693500.291805:led_change_intensity LED desc:'front-power-3' color:gre= en intensity 100% -> 0% 1592693500.312041:led_change_intensity LED desc:'front-power-3' color:gre= en intensity 0% -> 100% 1592693500.821254:led_change_intensity LED desc:'front-power-3' color:gre= en intensity 100% -> 0% 1592693501.331517:led_change_intensity LED desc:'front-power-3' color:gre= en intensity 0% -> 100% 1592693501.841367:led_change_intensity LED desc:'front-power-3' color:gre= en intensity 100% -> 0% 1592693502.350839:led_change_intensity LED desc:'front-power-3' color:gre= en intensity 0% -> 100% 1592693502.861134:led_change_intensity LED desc:'front-power-3' color:gre= en intensity 100% -> 0% 1592693503.371090:led_change_intensity LED desc:'front-power-3' color:gre= en intensity 0% -> 100% We notice the front-power LED starts to blink at a ~2Hz rate. Reviewed-by: Richard Henderson Reviewed-by: Luc Michel Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: C=C3=A9dric Le Goater Message-Id: <20200912134041.946260-5-f4bug@amsat.org> --- hw/arm/aspeed.c | 20 ++++++++++++++++++++ hw/arm/Kconfig | 1 + 2 files changed, 21 insertions(+) diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c index bdb981d2f87..0ef3f6b412f 100644 --- a/hw/arm/aspeed.c +++ b/hw/arm/aspeed.c @@ -20,6 +20,7 @@ #include "hw/i2c/smbus_eeprom.h" #include "hw/misc/pca9552.h" #include "hw/misc/tmp105.h" +#include "hw/misc/led.h" #include "hw/qdev-properties.h" #include "qemu/log.h" #include "sysemu/block-backend.h" @@ -525,9 +526,20 @@ static void sonorapass_bmc_i2c_init(AspeedMachineState= *bmc) =20 static void witherspoon_bmc_i2c_init(AspeedMachineState *bmc) { + static const struct { + unsigned gpio_id; + LEDColor color; + const char *description; + bool gpio_polarity; + } pca1_leds[] =3D { + {13, LED_COLOR_GREEN, "front-fault-4", GPIO_POLARITY_ACTIVE_LOW}, + {14, LED_COLOR_GREEN, "front-power-3", GPIO_POLARITY_ACTIVE_LOW}, + {15, LED_COLOR_GREEN, "front-id-5", GPIO_POLARITY_ACTIVE_LOW}, + }; AspeedSoCState *soc =3D &bmc->soc; uint8_t *eeprom_buf =3D g_malloc0(8 * 1024); DeviceState *dev; + LEDState *led; =20 /* Bus 3: TODO bmp280@77 */ /* Bus 3: TODO max31785@52 */ @@ -538,6 +550,14 @@ static void witherspoon_bmc_i2c_init(AspeedMachineStat= e *bmc) aspeed_i2c_get_bus(&soc->i2c, 3), &error_fatal); =20 + for (size_t i =3D 0; i < ARRAY_SIZE(pca1_leds); i++) { + led =3D led_create_simple(OBJECT(bmc), + pca1_leds[i].gpio_polarity, + pca1_leds[i].color, + pca1_leds[i].description); + qdev_connect_gpio_out(dev, pca1_leds[i].gpio_id, + qdev_get_gpio_in(DEVICE(led), 0)); + } i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 4), "tmp423", 0x= 4c); i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 5), "tmp423", 0x= 4c); =20 diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 7d040827af4..70e275cafda 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -404,6 +404,7 @@ config ASPEED_SOC select TMP105 select TMP421 select UNIMP + select LED =20 config MPS2 bool --=20 2.26.2 From nobody Mon Nov 17 09:50:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.218.54 as permitted sender) client-ip=209.85.218.54; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ej1-f54.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.218.54 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1603750019; cv=none; d=zohomail.com; s=zohoarc; b=Ghu2pnd/+4QVtN0S+TMsMf6aLulLW4t7pI1ZktHi5T9p2FYjocbW+nhB8g5oFXRWz4buyU7MslryleOgNOwa9fK7F8uMMGtDLZmsJNlrNtacTKFyslXy1waErukQJ5rUKgJhosT7u7OLpNQbPPMbRZ4z5nzpo4wgUia7at/pmIg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603750019; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oZ59K3EUFY4um2tzgzmnbro06kh/DapJGr61n3bGzJU=; b=X0OJQmYFJEFkvjIQ4bIWLz6soujg85LATg61wPNrJ3O3QCUV2c5hY/ncTQ2Nzr7cuGevZ8ZEAT8lDAxVgky9IpjBjzdlnKmpyHXVXV8PX/lxOTt53fKdx9m5F42ARUCPYglAiRFyoSVRonxTa2YuaMExhebWnfFEpU/I2nG9G2A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.218.54 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by mx.zohomail.com with SMTPS id 1603750019020527.2525030837968; Mon, 26 Oct 2020 15:06:59 -0700 (PDT) Received: by mail-ej1-f54.google.com with SMTP id c15so16121813ejs.0 for ; Mon, 26 Oct 2020 15:06:58 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (237.red-88-18-140.staticip.rima-tde.net. [88.18.140.237]) by smtp.gmail.com with ESMTPSA id c14sm5869102edy.13.2020.10.26.15.06.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 15:06:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oZ59K3EUFY4um2tzgzmnbro06kh/DapJGr61n3bGzJU=; b=hs55KhvKDi4acDEDW1Tmk98gdFW6cYfhLJBI4NLLJG1xfLWBSJxQ0g4gdepB3K4pIz FwKo5HQx0Mqd0vF+jJ/LjjSJe3gv4JAMShsMnG8YCJSaBfjTJwpsVi3Gb6wl86GjuAWQ 8+RhkaC5U9Mxut9UXgPlCHA7cHala162JyT2yrKXHoJFFrKUgSmxN/Nu+RXUbsoreaus ZD3+8S0z4h1DyD3gJ+W3763W+te2fcWfqmhN/2TiE4YTaSo19AhSnItS6drAI1sCbeCi BnJKcpiqU13Y/8xMbJNPBXV5J7PF2OSAhkgw54pbT9M/G2Iu7QY2LYY5GQd9c/+qIteU s5NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=oZ59K3EUFY4um2tzgzmnbro06kh/DapJGr61n3bGzJU=; b=NbDM1Q7g8YVUKbkmShnhCEjSb5DEyBXwrjNZobj2NTl+w6aL18+WaUn+cIUnACn4gc 39HmZVskwAq/d6xK4wMTxHn7ZTyvOjuU0NtprD69OYsB6OOcPg1mjixaX1DEN10Ob0Of blI43ojr+hB9cBcYYWClcX1ybii04ws3PWLESfPBjNTFWv0snobdvcgi07Cac+QvaLID mbuRsLH+ULAFdExQ4P9t1P1pHBX60XqokxEXvs0AWdUX5fPGTRBcRZxCUTcChaCC8Wsm l0+9gA/SEBnzSR9oQ04iNcB6iVuParw1Gysxa6nGLEF5L+2Z94JXqHX1v3rK2orAM5Dp eBbA== X-Gm-Message-State: AOAM533McCpXHoVtjxTx6B2vIqvPy7qrXudftNVIhQUDRpYCF384LAz+ 2WD7QhdDL8LW/geutkxwNCo= X-Google-Smtp-Source: ABdhPJzi+Xn6EHR1mnORqwvxk/3IbGO9WdS6dc6tM7syNjnepocKBXGThx96c7EO9sxvo4NKyms4tg== X-Received: by 2002:a17:906:802:: with SMTP id e2mr17454358ejd.294.1603750016997; Mon, 26 Oct 2020 15:06:56 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Andrew Jeffery , Joel Stanley , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Andrzej Zaborowski , qemu-arm@nongnu.org, Paolo Bonzini , Peter Maydell , Richard Henderson , Luc Michel Subject: [PULL 5/7] hw/misc/mps2-fpgaio: Use the LED device Date: Mon, 26 Oct 2020 23:06:22 +0100 Message-Id: <20201026220624.60878-6-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026220624.60878-1-f4bug@amsat.org> References: <20201026220624.60878-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) Per the 'ARM MPS2 and MPS2+ FPGA Prototyping Boards Technical Reference Manual' (100112_0200_07_en): 2.1 Overview of the MPS2 and MPS2+ hardware The MPS2 and MPS2+ FPGA Prototyping Boards contain the following components and interfaces: * User switches and user LEDs: - Two green LEDs and two push buttons that connect to the FPGA. - Eight green LEDs and one 8-way dip switch that connect to the MCC. Add the 2 LEDs connected to the FPGA. This replaces the 'mps2_fpgaio_leds' trace events by the generic 'led_set_intensity' event. Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Luc Michel Message-Id: <20200912134041.946260-6-f4bug@amsat.org> --- include/hw/misc/mps2-fpgaio.h | 2 ++ hw/misc/mps2-fpgaio.c | 23 ++++++++++++++++++----- hw/misc/Kconfig | 1 + hw/misc/trace-events | 1 - 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/hw/misc/mps2-fpgaio.h b/include/hw/misc/mps2-fpgaio.h index 80f9227aa66..a010fdb2b6d 100644 --- a/include/hw/misc/mps2-fpgaio.h +++ b/include/hw/misc/mps2-fpgaio.h @@ -22,6 +22,7 @@ #define MPS2_FPGAIO_H =20 #include "hw/sysbus.h" +#include "hw/misc/led.h" #include "qom/object.h" =20 #define TYPE_MPS2_FPGAIO "mps2-fpgaio" @@ -33,6 +34,7 @@ struct MPS2FPGAIO { =20 /*< public >*/ MemoryRegion iomem; + LEDState *led[2]; =20 uint32_t led0; uint32_t prescale; diff --git a/hw/misc/mps2-fpgaio.c b/hw/misc/mps2-fpgaio.c index 2f3fbeef348..6af0e8f837a 100644 --- a/hw/misc/mps2-fpgaio.c +++ b/hw/misc/mps2-fpgaio.c @@ -24,6 +24,7 @@ #include "migration/vmstate.h" #include "hw/registerfields.h" #include "hw/misc/mps2-fpgaio.h" +#include "hw/misc/led.h" #include "hw/qdev-properties.h" #include "qemu/timer.h" =20 @@ -176,12 +177,9 @@ static void mps2_fpgaio_write(void *opaque, hwaddr off= set, uint64_t value, =20 switch (offset) { case A_LED0: - /* LED bits [1:0] control board LEDs. We don't currently have - * a mechanism for displaying this graphically, so use a trace eve= nt. - */ - trace_mps2_fpgaio_leds(value & 0x02 ? '*' : '.', - value & 0x01 ? '*' : '.'); s->led0 =3D value & 0x3; + led_set_state(s->led[0], value & 0x01); + led_set_state(s->led[1], value & 0x02); break; case A_PRESCALE: resync_counter(s); @@ -239,6 +237,10 @@ static void mps2_fpgaio_reset(DeviceState *dev) s->counter =3D 0; s->pscntr =3D 0; s->pscntr_sync_ticks =3D now; + + for (size_t i =3D 0; i < ARRAY_SIZE(s->led); i++) { + device_cold_reset(DEVICE(s->led[i])); + } } =20 static void mps2_fpgaio_init(Object *obj) @@ -251,6 +253,16 @@ static void mps2_fpgaio_init(Object *obj) sysbus_init_mmio(sbd, &s->iomem); } =20 +static void mps2_fpgaio_realize(DeviceState *dev, Error **errp) +{ + MPS2FPGAIO *s =3D MPS2_FPGAIO(dev); + + s->led[0] =3D led_create_simple(OBJECT(dev), GPIO_POLARITY_ACTIVE_HIGH, + LED_COLOR_GREEN, "USERLED0"); + s->led[1] =3D led_create_simple(OBJECT(dev), GPIO_POLARITY_ACTIVE_HIGH, + LED_COLOR_GREEN, "USERLED1"); +} + static bool mps2_fpgaio_counters_needed(void *opaque) { /* Currently vmstate.c insists all subsections have a 'needed' functio= n */ @@ -299,6 +311,7 @@ static void mps2_fpgaio_class_init(ObjectClass *klass, = void *data) DeviceClass *dc =3D DEVICE_CLASS(klass); =20 dc->vmsd =3D &mps2_fpgaio_vmstate; + dc->realize =3D mps2_fpgaio_realize; dc->reset =3D mps2_fpgaio_reset; device_class_set_props(dc, mps2_fpgaio_properties); } diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig index e4d059591ad..7e9a8a443a5 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -93,6 +93,7 @@ config MIPS_ITU =20 config MPS2_FPGAIO bool + select LED =20 config MPS2_SCC bool diff --git a/hw/misc/trace-events b/hw/misc/trace-events index 6bf7ce863fb..52e637bf4c3 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -92,7 +92,6 @@ mps2_scc_cfg_read(unsigned function, unsigned device, uin= t32_t value) "MPS2 SCC mps2_fpgaio_read(uint64_t offset, uint64_t data, unsigned size) "MPS2 FPGA= IO read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" mps2_fpgaio_write(uint64_t offset, uint64_t data, unsigned size) "MPS2 FPG= AIO write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" mps2_fpgaio_reset(void) "MPS2 FPGAIO: reset" -mps2_fpgaio_leds(char led1, char led0) "MPS2 FPGAIO LEDs: %c%c" =20 # msf2-sysreg.c msf2_sysreg_write(uint64_t offset, uint32_t val, uint32_t prev) "msf2-sysr= eg write: addr 0x%08" PRIx64 " data 0x%" PRIx32 " prev 0x%" PRIx32 --=20 2.26.2 From nobody Mon Nov 17 09:50:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.218.48 as permitted sender) client-ip=209.85.218.48; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ej1-f48.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.218.48 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1603750024; cv=none; d=zohomail.com; s=zohoarc; b=AMKNk8RpM/uXrHHn8UjDIB9mI7rUblSN0UMcnqbTBc5tDj8lCaTcxqywoUUkhfKOf4yEzEzj/WWB4Nt1uFqzLhnlbcYnMRUrWp1sEAtDDYwoRyTM9+HTFV+0bKCF3QYsH9jr/MgbCCP6ldpM4At3Oj7BO/M1oYk+TEe+I8+C508= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603750024; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JOdGGIzrIruaPKwzTz9S2BIqCSeFSBaRFOdm0Fn9vaU=; b=XKbJST9tdARNg8Fwp+vNbniV9+ZtKf/jJCSExGPTYQeHm5oLGJk5J+SLgBHHji5L6RGP++kovhcKXyirGn9Ufu2jkouFQ0xUtDt737JuzU+bf2DrkLyiFJHYD3qxN/yTeFJThtDEh02PKlIGAewm0uWI47wJtFGc/LepdC9mRXA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.218.48 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) by mx.zohomail.com with SMTPS id 160375002463275.18515022364363; Mon, 26 Oct 2020 15:07:04 -0700 (PDT) Received: by mail-ej1-f48.google.com with SMTP id s15so11538527ejf.8 for ; Mon, 26 Oct 2020 15:07:03 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (237.red-88-18-140.staticip.rima-tde.net. [88.18.140.237]) by smtp.gmail.com with ESMTPSA id w25sm6590139ejy.123.2020.10.26.15.07.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 15:07:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JOdGGIzrIruaPKwzTz9S2BIqCSeFSBaRFOdm0Fn9vaU=; b=NTS7IV04nM+PMG9+XdA/DJoz+pHIWWfwpVS+HwSpKdOpVhVgfXH0+PKtpLGil0cyzD i6XSH3RrJsYNoeSDH7hDGXtbdr73d+To3WNondmrKFJ/IvOzdTvKB0FhB2WWOVA7yYzx i9wvh+8TWBp0D36Ai5etBjl4bepp0+JuW74R+NAsXb17sCwbIAHkWGpmOwNhce8Y03cq YzWV5pOaVbLs+Ph60W5HD1+uj6H7bNrDmormL7dIlbmFlA0B+svKT8wqGsn3gcyOlBtg 03gAt/aYYOnKxDUxiFTHtqTU/jyN2ruvlAPfk4DKNVGuDDil8lVtAOv0ac6kvCkmVEh1 Z2og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=JOdGGIzrIruaPKwzTz9S2BIqCSeFSBaRFOdm0Fn9vaU=; b=OkjhYKyao5ZU5zCtLoowkWpZoMpFDMjAqy37/qRDXq6k8KlyffmDJdIgKhMf+CkKzU UUwDhz2iJeRfpaFeHS+2U7mocpVN95295VCETQC4tRpBi5x4FD1r/c+byk+ybR3tONUj cFi9Ze5cLpqKECRwpzuPG8COXK1RmEQ34LnT9zqEMcA9mHsbjUCj0Ier3TgKsE1GHGfz fh5AavBcioALqrGkvJfT2+Kb/vUtLBP1wwMPd9t5My8kTE++OnClx/0NDwFec4MXeggR rswyzQAS7YbsP653WXIdqTvDuLetHGNRB6gP3mYFpMKKC6NRMfb4kj+w8Jx1aNh63XR+ a59Q== X-Gm-Message-State: AOAM5301t725dUZiftsdAFNt3reBDJj9W6OoURUNC1B03Bpg9MrV27d+ 2gT43bBd6W8JNPulpYtHsdc= X-Google-Smtp-Source: ABdhPJxfsAcLnliW2DdMpMJ61m+rYeGeY0pZfS3oVKizHLzlSdzSAt8/P70TmtVbU0o6tVY9BlCgdQ== X-Received: by 2002:a17:906:6453:: with SMTP id l19mr17915173ejn.366.1603750022630; Mon, 26 Oct 2020 15:07:02 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Andrew Jeffery , Joel Stanley , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Andrzej Zaborowski , qemu-arm@nongnu.org, Paolo Bonzini , Peter Maydell , Richard Henderson , Luc Michel Subject: [PULL 6/7] hw/misc/mps2-scc: Use the LED device Date: Mon, 26 Oct 2020 23:06:23 +0100 Message-Id: <20201026220624.60878-7-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026220624.60878-1-f4bug@amsat.org> References: <20201026220624.60878-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) Per the 'ARM MPS2 and MPS2+ FPGA Prototyping Boards Technical Reference Manual' (100112_0200_07_en): 2.1 Overview of the MPS2 and MPS2+ hardware The MPS2 and MPS2+ FPGA Prototyping Boards contain the following components and interfaces: * User switches and user LEDs: - Two green LEDs and two push buttons that connect to the FPGA. - Eight green LEDs and one 8-way dip switch that connect to the MCC. Add the 8 LEDs connected to the MCC. This replaces the 'mps2_scc_leds' trace events by the generic 'led_set_intensity' event. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Reviewed-by: Luc Michel Message-Id: <20200912134041.946260-7-f4bug@amsat.org> --- include/hw/misc/mps2-scc.h | 2 ++ hw/misc/mps2-scc.c | 27 ++++++++++++++++----------- hw/misc/Kconfig | 1 + hw/misc/trace-events | 1 - 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/hw/misc/mps2-scc.h b/include/hw/misc/mps2-scc.h index e922b3c8e0d..f65d8732031 100644 --- a/include/hw/misc/mps2-scc.h +++ b/include/hw/misc/mps2-scc.h @@ -13,6 +13,7 @@ #define MPS2_SCC_H =20 #include "hw/sysbus.h" +#include "hw/misc/led.h" #include "qom/object.h" =20 #define TYPE_MPS2_SCC "mps2-scc" @@ -26,6 +27,7 @@ struct MPS2SCC { =20 /*< public >*/ MemoryRegion iomem; + LEDState *led[8]; =20 uint32_t cfg0; uint32_t cfg1; diff --git a/hw/misc/mps2-scc.c b/hw/misc/mps2-scc.c index 9d0909e7b35..ce1dfe93562 100644 --- a/hw/misc/mps2-scc.c +++ b/hw/misc/mps2-scc.c @@ -20,11 +20,13 @@ #include "qemu/osdep.h" #include "qemu/log.h" #include "qemu/module.h" +#include "qemu/bitops.h" #include "trace.h" #include "hw/sysbus.h" #include "migration/vmstate.h" #include "hw/registerfields.h" #include "hw/misc/mps2-scc.h" +#include "hw/misc/led.h" #include "hw/qdev-properties.h" =20 REG32(CFG0, 0) @@ -152,18 +154,10 @@ static void mps2_scc_write(void *opaque, hwaddr offse= t, uint64_t value, s->cfg0 =3D value; break; case A_CFG1: - /* CFG1 bits [7:0] control the board LEDs. We don't currently have - * a mechanism for displaying this graphically, so use a trace eve= nt. - */ - trace_mps2_scc_leds(value & 0x80 ? '*' : '.', - value & 0x40 ? '*' : '.', - value & 0x20 ? '*' : '.', - value & 0x10 ? '*' : '.', - value & 0x08 ? '*' : '.', - value & 0x04 ? '*' : '.', - value & 0x02 ? '*' : '.', - value & 0x01 ? '*' : '.'); s->cfg1 =3D value; + for (size_t i =3D 0; i < ARRAY_SIZE(s->led); i++) { + led_set_state(s->led[i], extract32(value, i, 1)); + } break; case A_CFGDATA_OUT: s->cfgdata_out =3D value; @@ -236,6 +230,9 @@ static void mps2_scc_reset(DeviceState *dev) for (i =3D 0; i < NUM_OSCCLK; i++) { s->oscclk[i] =3D s->oscclk_reset[i]; } + for (i =3D 0; i < ARRAY_SIZE(s->led); i++) { + device_cold_reset(DEVICE(s->led[i])); + } } =20 static void mps2_scc_init(Object *obj) @@ -249,6 +246,14 @@ static void mps2_scc_init(Object *obj) =20 static void mps2_scc_realize(DeviceState *dev, Error **errp) { + MPS2SCC *s =3D MPS2_SCC(dev); + + for (size_t i =3D 0; i < ARRAY_SIZE(s->led); i++) { + char *name =3D g_strdup_printf("SCC LED%zu", i); + s->led[i] =3D led_create_simple(OBJECT(dev), GPIO_POLARITY_ACTIVE_= HIGH, + LED_COLOR_GREEN, name); + g_free(name); + } } =20 static const VMStateDescription mps2_scc_vmstate =3D { diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig index 7e9a8a443a5..877ecff4477 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -97,6 +97,7 @@ config MPS2_FPGAIO =20 config MPS2_SCC bool + select LED =20 config TZ_MPC bool diff --git a/hw/misc/trace-events b/hw/misc/trace-events index 52e637bf4c3..c68811b670c 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -84,7 +84,6 @@ aspeed_scu_write(uint64_t offset, unsigned size, uint32_t= data) "To 0x%" PRIx64 mps2_scc_read(uint64_t offset, uint64_t data, unsigned size) "MPS2 SCC rea= d: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" mps2_scc_write(uint64_t offset, uint64_t data, unsigned size) "MPS2 SCC wr= ite: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" mps2_scc_reset(void) "MPS2 SCC: reset" -mps2_scc_leds(char led7, char led6, char led5, char led4, char led3, char = led2, char led1, char led0) "MPS2 SCC LEDs: %c%c%c%c%c%c%c%c" mps2_scc_cfg_write(unsigned function, unsigned device, uint32_t value) "MP= S2 SCC config write: function %d device %d data 0x%" PRIx32 mps2_scc_cfg_read(unsigned function, unsigned device, uint32_t value) "MPS= 2 SCC config read: function %d device %d data 0x%" PRIx32 =20 --=20 2.26.2 From nobody Mon Nov 17 09:50:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.218.65 as permitted sender) client-ip=209.85.218.65; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ej1-f65.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.218.65 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=fail(p=none dis=none) header.from=amsat.org ARC-Seal: i=1; a=rsa-sha256; t=1603750030; cv=none; d=zohomail.com; s=zohoarc; b=M6tjIEuJHwuEAYnw/+qMod03Fg1rMKQg+ix6MwXeJICLpicXKhnBcAYeI8rbCgqr8pQm45ThB0LkBrzxoioXkp0/zoPqsFRvmZfOUmOJdX5VeKyyHDxz0mAZvvdYVYD4NGB9YCNgfE0mz5+/f8QVvq+rbJWLujKnjZAm1ikuwak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603750030; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Cm68ZLDWvK5znkWhn2IKM56HcHBW6UWkfpIBdHv6B2I=; b=nBU/NPY91OsHbsjaM0/l3WkrO9HRvj/81EVI/K0wGA+rMfswDfncU3/Fo5Dww6W56udL8UxKRD3JxFoN+Biqze9BMRaT0jaO1zEcW+qh9ApNrhGq84RaBFUKPMLmO58bDnl8fd0wGHIZYyY+xb/gSPfaSwjAx4BNw5elyYnwfoI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.218.65 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by mx.zohomail.com with SMTPS id 1603750030493226.80633510008101; Mon, 26 Oct 2020 15:07:10 -0700 (PDT) Received: by mail-ej1-f65.google.com with SMTP id gs25so16129372ejb.1 for ; Mon, 26 Oct 2020 15:07:09 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (237.red-88-18-140.staticip.rima-tde.net. [88.18.140.237]) by smtp.gmail.com with ESMTPSA id s25sm6427447ejc.29.2020.10.26.15.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 15:07:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Cm68ZLDWvK5znkWhn2IKM56HcHBW6UWkfpIBdHv6B2I=; b=KqRdWZL2zYIVybTEFN2IcvQZZGH6zfluL0WwUvMHZrqaBXCPAEfqgb76XoBaFQ1H5V Cw7t++uxDZjxd4HLJt9rYwEt5QxSSvUjRhUW9nzFh6aoYmOqDSK2OZQTPBlJIxSwhr6+ WYdtfk+B/nSoPo0AGHAC/DAF8yUEr6DlANjGe9VSJS7UHFcXBZH/BMVo2fh8G7Koxs7L 5et5ho9z6KQ0PwMKvdITZnkBsgXS323DRZ7ZUCMHUGjZh7PThxj12nK9kAJn0g0x5I/a aqGHF6PpptOE095N8djbPKWE4GlArRkvFnLyj5arSNEUNV8OwSn5unx/w9XOkccCq92T guHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Cm68ZLDWvK5znkWhn2IKM56HcHBW6UWkfpIBdHv6B2I=; b=ZdrLHxfi5g4NilV0EiiUgCxZuDQP7Y3+IPaDRr4UbvHsnzsZBsacUN+xgOuKrbZn+V le1kBWDoomCEaaTOGCqwrsX2kn8twQGHnYwZ7ViV7WdVCEpx+eaDaBP/ZN1EBVMLTol7 5Y/Pd4Zas3EX217v41oZwhChKcXaOqWeFyUGBF3/17kWl0AhEiBTlruaafo8Remjon69 G/SI6VfUE7gJzZTcl/7GBq20XT6PYaJOgj/VthjWfRf/awATn8Zi6meSWgyo1QxYWdtD bu2RaUSS+GOX3dm5kJIMIhD0ZQXBKrYngh5Fr8UlVpepU405ETOewVrnce8LhK7WS48K 16Ww== X-Gm-Message-State: AOAM532wp72XWaJ/Y5Uw9gF8iLuUzpC/RTty53zd2xFwjbrUBRrvZlBq PohMtIXAwjn1ldcGolaz6Mg= X-Google-Smtp-Source: ABdhPJyNdpmQrhFqo1WYNDZI5qJD1CF4hrCEtMlK2Unx0f6R7b/Yrbj+J+dyfPwpCi7FVO8h9J8HBg== X-Received: by 2002:a17:906:14db:: with SMTP id y27mr18600472ejc.148.1603750028476; Mon, 26 Oct 2020 15:07:08 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Andrew Jeffery , Joel Stanley , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Andrzej Zaborowski , qemu-arm@nongnu.org, Paolo Bonzini , Peter Maydell , Luc Michel , Richard Henderson Subject: [PULL 7/7] hw/arm/tosa: Replace fprintf() calls by LED devices Date: Mon, 26 Oct 2020 23:06:24 +0100 Message-Id: <20201026220624.60878-8-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201026220624.60878-1-f4bug@amsat.org> References: <20201026220624.60878-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) The recently added LED device reports LED status changes with the 'led_set_intensity' trace event. It is less invasive than the fprintf() calls. We need however to have a binary built with tracing support. Reviewed-by: Luc Michel Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20200912134041.946260-8-f4bug@amsat.org> --- hw/arm/tosa.c | 40 +++++++++++++++------------------------- hw/arm/Kconfig | 1 + 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/hw/arm/tosa.c b/hw/arm/tosa.c index c196f0d2f88..fe88ed89fee 100644 --- a/hw/arm/tosa.c +++ b/hw/arm/tosa.c @@ -24,6 +24,7 @@ #include "hw/irq.h" #include "hw/ssi/ssi.h" #include "hw/sysbus.h" +#include "hw/misc/led.h" #include "exec/address-spaces.h" #include "qom/object.h" =20 @@ -81,26 +82,6 @@ struct TosaMiscGPIOState { SysBusDevice parent_obj; }; =20 -static void tosa_gpio_leds(void *opaque, int line, int level) -{ - switch (line) { - case 0: - fprintf(stderr, "blue LED %s.\n", level ? "on" : "off"); - break; - case 1: - fprintf(stderr, "green LED %s.\n", level ? "on" : "off"); - break; - case 2: - fprintf(stderr, "amber LED %s.\n", level ? "on" : "off"); - break; - case 3: - fprintf(stderr, "wlan LED %s.\n", level ? "on" : "off"); - break; - default: - g_assert_not_reached(); - } -} - static void tosa_reset(void *opaque, int line, int level) { if (level) { @@ -112,7 +93,6 @@ static void tosa_misc_gpio_init(Object *obj) { DeviceState *dev =3D DEVICE(obj); =20 - qdev_init_gpio_in_named(dev, tosa_gpio_leds, "leds", 4); qdev_init_gpio_in_named(dev, tosa_reset, "reset", 1); } =20 @@ -122,6 +102,7 @@ static void tosa_gpio_setup(PXA2xxState *cpu, TC6393xbState *tmio) { DeviceState *misc_gpio; + LEDState *led[4]; =20 misc_gpio =3D sysbus_create_simple(TYPE_TOSA_MISC_GPIO, -1, NULL); =20 @@ -143,14 +124,23 @@ static void tosa_gpio_setup(PXA2xxState *cpu, qdev_get_gpio_in(cpu->gpio, TOSA_GPIO_JC_CF_IRQ), NULL); =20 + led[0] =3D led_create_simple(OBJECT(misc_gpio), GPIO_POLARITY_ACTIVE_H= IGH, + LED_COLOR_BLUE, "bluetooth"); + led[1] =3D led_create_simple(OBJECT(misc_gpio), GPIO_POLARITY_ACTIVE_H= IGH, + LED_COLOR_GREEN, "note"); + led[2] =3D led_create_simple(OBJECT(misc_gpio), GPIO_POLARITY_ACTIVE_H= IGH, + LED_COLOR_AMBER, "charger-error"); + led[3] =3D led_create_simple(OBJECT(misc_gpio), GPIO_POLARITY_ACTIVE_H= IGH, + LED_COLOR_GREEN, "wlan"); + qdev_connect_gpio_out(scp1, TOSA_GPIO_BT_LED, - qdev_get_gpio_in_named(misc_gpio, "leds", 0)); + qdev_get_gpio_in(DEVICE(led[0]), 0)); qdev_connect_gpio_out(scp1, TOSA_GPIO_NOTE_LED, - qdev_get_gpio_in_named(misc_gpio, "leds", 1)); + qdev_get_gpio_in(DEVICE(led[1]), 0)); qdev_connect_gpio_out(scp1, TOSA_GPIO_CHRG_ERR_LED, - qdev_get_gpio_in_named(misc_gpio, "leds", 2)); + qdev_get_gpio_in(DEVICE(led[2]), 0)); qdev_connect_gpio_out(scp1, TOSA_GPIO_WLAN_LED, - qdev_get_gpio_in_named(misc_gpio, "leds", 3)); + qdev_get_gpio_in(DEVICE(led[3]), 0)); =20 qdev_connect_gpio_out(scp1, TOSA_GPIO_TC6393XB_L3V_ON, tc6393xb_l3v_ge= t(tmio)); =20 diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 70e275cafda..3c893e07cde 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -151,6 +151,7 @@ config TOSA select ZAURUS # scoop select MICRODRIVE select PXA2XX + select LED =20 config SPITZ bool --=20 2.26.2