From nobody Thu May 2 09:32:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.67 as permitted sender) client-ip=209.85.221.67; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f67.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.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=1599918047; cv=none; d=zohomail.com; s=zohoarc; b=nVtwjRgkM/ZkJQwC412/508TZWsnLnr1OR1N+6mApQJJiFSqe5wSEDMp06V3rhl5dAC5e8QOLd8q8DVyenBN5gwgg6rxLfi+mzgWA01KYyEjoDKXrf+7aHWQJGHa+zXV9bTATvcDR0AobztSBVtV4rbEbJu1QXGMS+J6fhtiPhk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599918047; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=y86HzAI5lMj9ngzCCe5i/3UqscAo/bm2D9jSWhWdSS4=; b=lY3vH/fqmB3swqYkGz4fiTUcwKKaEwzBy37/OLgntfy5s8N3+Hcnq5a0R+961Rqoj29UPzqPgwk2ZttjIFmW9d9EvG7wJsp75tkQM1Zv4a821HlWDTX9npF93iiDwShbqrbcvYW9pDcl7nqQA+1WVG9SK5L1fm/ghrp1jwbXBwA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.67 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by mx.zohomail.com with SMTPS id 1599918047767393.64712234670685; Sat, 12 Sep 2020 06:40:47 -0700 (PDT) Received: by mail-wr1-f67.google.com with SMTP id e16so14119935wrm.2 for ; Sat, 12 Sep 2020 06:40:47 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id u66sm10309144wmg.44.2020.09.12.06.40.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Sep 2020 06:40:45 -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=y86HzAI5lMj9ngzCCe5i/3UqscAo/bm2D9jSWhWdSS4=; b=ZvS3ozl1nKz1XUELao8i+iUwaUJOx7LVehkYZZBEtmW5fRcviSIeEG4JQ+vyR3bSST iRtSAuQmgFdwiiGl8iEKAOTrLn1oEzmCklYxUTso8HvxYZQPrNhnlnUYSW8lME1B8+1V suS/QSW+jTPaUyU8UmPuMdoT2ND2C1QxTHZ2vgXTnu0P5jneNGwWO6CVa5IsGfA1Xa7d 8v88UJa/qU9XYiuaUL8CO8fsoufeZ59WDmrvpHh7UgtBihu3ycJbfZeqc/q/psD7Nq7I +Td6HX576Q8qzkYIx2W4Q9QZ4QKZ3yS5Q/gmonAb3E4qKWRqo8NODJ3mDLpQ+F0KIm8J /qWw== 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=y86HzAI5lMj9ngzCCe5i/3UqscAo/bm2D9jSWhWdSS4=; b=pVF6oue8KpnQI4U35V6JcqTZoJNyCbI6DLu9+h7jHA4gVTdad3s+inOiwn2ZaHW8Kn aHBa+4mvkAq4uvIlNBd8GpxL2Co/kW2ckdsVg5er4lQ56Qd5DHP5YWo6H5OKmpLtCy6q mZx9LZUvrnTgjtasMdNsbzz9zJGX5EKRF5sstAyxHjzvbcQ+YCutVl6DNFpVP0uSf0ba N60yd0ADO98OC6v36xG0PMq9l8gTC+5AAuRHRlyw++xAQ8s4wkMdFhrquuo2woGj6e9a 76KKK/P53P9WFGyd2NFexuPYYl3diGiiJ7dbdnBgkzUn1pBnpYN5tZdU/V6hV6ys+mL8 Kb4w== X-Gm-Message-State: AOAM532pDNwoCRQUM5OdQUP4uLa7/Sd59pbuX9njSh77GXfSn2kKZ9PN 4ND4u2vDJWdasR63ZxvohoE= X-Google-Smtp-Source: ABdhPJwTonRRt8eDwSegb6g0eyoz1rpyx7xrXP178qqRe9nP5bKlMs+kbbAvpGeIjLfV1V3T0UHCHA== X-Received: by 2002:adf:a35d:: with SMTP id d29mr6915156wrb.307.1599918045702; Sat, 12 Sep 2020 06:40: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: Andrew Jeffery , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Peter Maydell , Luc Michel , Andrzej Zaborowski , Eduardo Habkost , qemu-arm@nongnu.org, Richard Henderson Subject: [PATCH v6 1/7] hw/misc/led: Add a LED device Date: Sat, 12 Sep 2020 15:40:35 +0200 Message-Id: <20200912134041.946260-2-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200912134041.946260-1-f4bug@amsat.org> References: <20200912134041.946260-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- 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 cf96fa83795..8886e48b4e6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1951,6 +1951,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 92c397ca07a..5c151fa3a83 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 e1576b81cf9..26f6dd037dc 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -11,6 +11,7 @@ softmmu_ss.add(when: 'CONFIG_TMP105', if_true: files('tmp= 105.c')) 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 56a622d1e97..211ff114694 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -215,6 +215,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 Thu May 2 09:32:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.67 as permitted sender) client-ip=209.85.221.67; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f67.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.67 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1599918049; cv=none; d=zohomail.com; s=zohoarc; b=I3PDYBTrxq3FHf0Y9lHg4rIQIp+LgcKLm5zSTGEt1CFOGtFJ2dr8RZWiEfUnCx5piMonyHI63wvDYrp9FOwy83Q72nuoeehn2j81xFAp4og0fks4LYvoQb8L9khqJHHyIzxKQT8uth9/PwlEoDcY4+Hpw5Jv/6+Jca7yIEWAbvM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599918049; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=w8Eo5/7klXOolpStkbQL0lu8B2pZTUunJlMPyHZPBkE=; b=Fc1DEu6zDzVdhtyjnxO9l9Mhv4xyy/Ekis3tR1ZLtUKYEthSAStulzCBBfl2iJqCu/p263EfCmcz5avqjhpVRg1DsajzYGLAFb2qcRBa9M9A6ZdgI6RW+zzFq0wSOZ76YJtDrBCSS9c/2tyrys5Z2UzaKl289jRagDmpoB23YgQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.67 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by mx.zohomail.com with SMTPS id 1599918049273961.6736173575712; Sat, 12 Sep 2020 06:40:49 -0700 (PDT) Received: by mail-wr1-f67.google.com with SMTP id z1so14103992wrt.3 for ; Sat, 12 Sep 2020 06:40:48 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id u66sm10309144wmg.44.2020.09.12.06.40.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Sep 2020 06:40:46 -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=w8Eo5/7klXOolpStkbQL0lu8B2pZTUunJlMPyHZPBkE=; b=uciR+5a5X9kHY5AYZgFmM7NhPz72lwUQmpehWGgPBVPbW1sxTyBC17FhEFSbfsadde Zv7LFOoe82E/xIKzAtxSVdbFCCYyf1k9A08g7vnnbZ12O004xEUG7paM5skUrWn6EFq/ f0BkNYYu6hMfj6pOM+mXd/rfsx0Wp7swL8CqGJmd8MWaCN3ce9UB38res5wB6TNFuFhM u61wsgZ2OmqeVyI6EcT2KRQ9FXvqhhj3KZLQ8BS46g3k8VHBlCD2dupHjNOfCAQjFx4v gkncRIMlVAs13S2oFqZjYhnb5NZq4TU/PJX70MJVDqqVgpk9CWqn3c5UQkPdZmE+cHrF z+VA== 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=w8Eo5/7klXOolpStkbQL0lu8B2pZTUunJlMPyHZPBkE=; b=dzCDv6peue/mXrRJGn4Uz31xquJMPJB+4vpzIIjiHA16z8dPiCYpSRqB7BFn69pS9T 6NcHtFJLUTQIdB21/u7Cmp9VU5VTnsxbsBRBJEJ1fDe55DxjfmMhZJCxj6r6LGcu2v9M J7PY+KjvyY1VJttdx8N1bJ4ErfuX58JvWnntp0jZTeaRbLLmow5YSJU+uqanJsTB7Hfx OC6h0viZ3z65AMyIfj5c4dBHHgCmsUSKwYc9J05f48VFLi623FLNOoC82PIu/neNG7/D gijr+jbqLsi2BfM1xcy6nqnS9LhawdjKKJFop8udTHtV8my4hGdad0yru5Cd9q0ODFxu H35A== X-Gm-Message-State: AOAM533qp6ExYc17GNb/voBlcYlleCBg9TrfzueoHcC2K0d65855Kbnb Z5eL2VC+1QeN83J80fPDsZA= X-Google-Smtp-Source: ABdhPJxRA+UTEeWLXheVHVA4YGt++jvqhZ+BJpD3sXZWTdvLfh57eeW6G/nyVzRtyfGiG5A2dWg2Lw== X-Received: by 2002:adf:f586:: with SMTP id f6mr6852900wro.299.1599918047130; Sat, 12 Sep 2020 06:40:47 -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: Andrew Jeffery , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Peter Maydell , Luc Michel , Andrzej Zaborowski , Eduardo Habkost , qemu-arm@nongnu.org Subject: [PATCH v6 2/7] hw/misc/led: Allow connecting from GPIO output Date: Sat, 12 Sep 2020 15:40:36 +0200 Message-Id: <20200912134041.946260-3-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200912134041.946260-1-f4bug@amsat.org> References: <20200912134041.946260-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: Luc Michel Reviewed-by: Richard Henderson --- 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 e025ba9653f..ec1f1efc37b 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -423,6 +423,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 Thu May 2 09:32:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.51 as permitted sender) client-ip=209.85.221.51; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f51.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.51 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1599918050; cv=none; d=zohomail.com; s=zohoarc; b=UJ6WJj4XDJGYAclBBmgikqXZTdvFkcvcqd6Wsa9qEEVYi5etejkZCHYuojFalH/JfP4NlCUK4K4GXYW/1Mnk++wHVr7aeqzmEONz9anEum94YhV/xqKBFNMrl5WbLqlnVwfjDd+Zc2sdJxvSmy8v6QnF+u16SPEgPiSQD0891hk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599918050; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dSaiRltAOJ/zxeobJcA1LXrUSnmjbfrE49BlQ0jwkLs=; b=UsL22WshPlafqW3UEsr9cfOOaQz8btx6l1faDeT+3APZtf7U+Qu+IuEgh3PhRWCZ54FJI6sESkYo6cia6MnvfhzLaTuUN0K8pCpbiItx+gGGVhkk9+uVAoDwDHCDv5e4RmMEyuTTsJ4YwNVagt/zMEvZLLr/GHmMf8Bv+qqx5Bw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.51 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by mx.zohomail.com with SMTPS id 1599918050541632.8320826156091; Sat, 12 Sep 2020 06:40:50 -0700 (PDT) Received: by mail-wr1-f51.google.com with SMTP id j2so14096692wrx.7 for ; Sat, 12 Sep 2020 06:40:49 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id u66sm10309144wmg.44.2020.09.12.06.40.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Sep 2020 06:40:48 -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=dSaiRltAOJ/zxeobJcA1LXrUSnmjbfrE49BlQ0jwkLs=; b=KJJ6UM1aUNnpaFueQ/03AK5N4pwtNsVK6FSFmmFvug0PXtNpZLPPw5SGbQAy61UsD5 +o+WmmKZFKGUsr3B37WtCDMdmqwnUYxb5psWrEDgICUO4sZOF6p01QngSCKfT4nP2+72 TwZbDsXQ7zfYq8/PqfGktzqgrjTa6DubNdACc6A++eDTTwe5kNhwQrb3mQox/03pptIP VDXVV4Jwc5RUrVK+evTAjFLL70CiRuDfwuXYYhE636jBDRpvMxLVZ6baY/PSS0R0cx85 nGkW6xKE6/ba1GcXAWIU8yw+5X21fNUI0ux+fol+g8L6Jm9d+pPUTgOyeiLhxh+0fs2T 4m7w== 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=dSaiRltAOJ/zxeobJcA1LXrUSnmjbfrE49BlQ0jwkLs=; b=AejEoqLP0A1LteDJ0hy9MWgjx8Pn1fIYJ+SgmzacIFWFRpmGsNBaX7nhztQiKcvBKB ecN6Ldyj/ghj+UoNIQ9aqmZG3Lkdg4M3RTr9zIPzSZARR8iOqDeih5yIHP7pqdBpBajX E4uNn2wFq/ezUalB8KlIcGdK02nGkKB1RhzZG+qTG7FY5jlXTriyXOfocw0feTFYWo9a b1HQeYI6tx/nqxpGd5XqAERv+cskat8N8D9b9MT7M2G5kE3Nrk7aDxd/1BBvWNf2o0IW BguMdIFFwrV+s/Ntoew6N/YqvVZPKSs0T+WW46K5OH7CZAXhHocbCB947LdXrjzIN37A 5UrQ== X-Gm-Message-State: AOAM533apPnnyRrnapS5Gg3GgND3kddhJmGBH8HqrpawlnH2ieNdFdcx Sv036gYeMPz9Y03LrSD/kWk= X-Google-Smtp-Source: ABdhPJyiwfHXP/Q206pIqJyyK9XNiRNJMQj30DnA8BxznmLeYZn2vVQEaloGAerdnh00AjBQYkj7ng== X-Received: by 2002:adf:e289:: with SMTP id v9mr6932636wri.14.1599918048595; Sat, 12 Sep 2020 06:40:48 -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: Andrew Jeffery , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Peter Maydell , Luc Michel , Andrzej Zaborowski , Eduardo Habkost , qemu-arm@nongnu.org, Richard Henderson Subject: [PATCH v6 3/7] hw/misc/led: Emit a trace event when LED intensity has changed Date: Sat, 12 Sep 2020 15:40:37 +0200 Message-Id: <20200912134041.946260-4-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200912134041.946260-1-f4bug@amsat.org> References: <20200912134041.946260-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- 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 211ff114694..5f3f6121bc9 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -217,6 +217,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 Thu May 2 09:32:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.128.67 as permitted sender) client-ip=209.85.128.67; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-f67.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.67 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1599918052; cv=none; d=zohomail.com; s=zohoarc; b=ZK+AVGZf8mt/05NBOH0bETCWC/amXYFnjvEea9H84oldGqoN0eiAAIdMONCyzQKMtI7jMMBGDEw05jICQ1IjMnSF09/QXRV6+YRCP2i9rHueLJZ8nSz3XyeBOS5LI8TdYSMWYNtg/NP3bqe575hentrLhnAi1AtJ6Xb4K9FpDu0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599918052; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dcziNR/TheFFTidKb7aVU6cyT7NZK4LKYIpEP4izZZI=; b=Tu3kxzz7I+HxKAkZxdwI7DtWTDrqUFmq9RB0tA3900jtP27N2tKqvlUzfVn0XqnZvI1Ot0kI9RfkZ7ZqKcoz3Njtv+axEy7kNbGqhChYVTo7bATYjOzGK1CVimzijoWda0HJ/QVAtBoWKUU5i4R7GrcNmW1RLfIX5BFNCE4NNVs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.67 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by mx.zohomail.com with SMTPS id 1599918052202300.78187124316537; Sat, 12 Sep 2020 06:40:52 -0700 (PDT) Received: by mail-wm1-f67.google.com with SMTP id k18so7194498wmj.5 for ; Sat, 12 Sep 2020 06:40:51 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id u66sm10309144wmg.44.2020.09.12.06.40.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Sep 2020 06:40:49 -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=dcziNR/TheFFTidKb7aVU6cyT7NZK4LKYIpEP4izZZI=; b=ITzPUlozKTs3MLNo9Opv5bjPAQxb3mcoO4GerxhHIiMzKhsQdE3E5wLRG/GChF6TJC Qjs31f9R72QXtZ2UchHjauA5b1Ei9mgKoa/OpXL/FrtXvOD6Y1jsfiyJv/kG/HVvmspC wEg5l7n3veXQTEA9W7mQodPzXoxEi2xYJnCShmd35hiBa1Nn1sr4Okhs9xMSM+z4fZn7 OffhTOM27zmcwTjcqZm20AqrEtum6bVwCi79z+IZx2YymszBNkXjCYMmZ6worsfFdOcT L+S1s645SjRjb53Dh0mapCanoO/30KD8SIysDuOdaByCKyqXu1m16gRH97TUXZvhjeYT NpgA== 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=dcziNR/TheFFTidKb7aVU6cyT7NZK4LKYIpEP4izZZI=; b=mKvEezGZVPRrP+kutP2TaCWcjjXIiDzjeP2DGKfMT75bdtpMMpkFHyjgcZbfAdoFf8 0Uh6BA0Otf/sx5fz2yGM98HsdEoYWXZfQhNeK/MJqsKKVwTJ0lbjbIFNpJFx4jH8p/I4 nQvkAgnUBr9/5PnCdgz2nFWr7ELWCJBeG0o6giJYwXuRgL1kTMl69Bq+4JT9n3z8R+vO lNpmc6PWooFhHsdCwEHFKmz7+92QQHiv9iCA8vT/AWiCEbGts8eI5huU/WqMHkyckxz1 alNKfUgWGu7lfYLAEgc+D3T8XFDgGtS11LAV1R4K7+zdrf/iplr7Is96xSRKPbhIGhy6 MW3g== X-Gm-Message-State: AOAM533De3i2f0qR79uWkczJhvWR1oMvayQHLV3ef33ErEovEPUMaQOe LMcGoSVtoTD8FHrhDcvXIIY= X-Google-Smtp-Source: ABdhPJxmEsMVymaDBn9BmFo/e9xFEp5NC3Vfo78nH2l4yUJ/DHw1tXxDC6kx71GMKk3kLfhoE8HHzQ== X-Received: by 2002:a1c:1902:: with SMTP id 2mr7346133wmz.26.1599918050157; Sat, 12 Sep 2020 06:40:50 -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: Andrew Jeffery , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Peter Maydell , Luc Michel , Andrzej Zaborowski , Eduardo Habkost , qemu-arm@nongnu.org, Richard Henderson Subject: [PATCH v6 4/7] hw/arm/aspeed: Add the 3 front LEDs drived by the PCA9552 #1 Date: Sat, 12 Sep 2020 15:40:38 +0200 Message-Id: <20200912134041.946260-5-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200912134041.946260-1-f4bug@amsat.org> References: <20200912134041.946260-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- 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 8bfb1c79ddc..83e322ea983 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" @@ -521,9 +522,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 */ @@ -534,6 +546,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 bc3a423940b..06ba1c355b1 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -394,6 +394,7 @@ config ASPEED_SOC select TMP105 select TMP421 select UNIMP + select LED =20 config MPS2 bool --=20 2.26.2 From nobody Thu May 2 09:32:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.128.51 as permitted sender) client-ip=209.85.128.51; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-f51.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.51 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1599918053; cv=none; d=zohomail.com; s=zohoarc; b=AOKk9Ihhu14IBQr3gB9Q3YA92LNqsj4bwBVgqw0BAKDOy5VV69NQR3wjJv4V+9romqeikqZEwoXxhEW/2M4l9FA/qynmdaatkwCP3SzWZpq/Km37kHiSUIE3j3+TwOVYlzTE336FkJxPT+B5U69JJ44FWusStTAdj9XRNBEXu+o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599918053; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bXijLj9sePf1x7H7g7xUVbfkwlSyCDahYBi9izMEMaE=; b=jwcL60tpW4EyEFkttrzpINK2Qti7WySp58vHqNvodSlYpd9TxLUgq/YEXJV17Li4dNRufqrUO6qcJ97y3n6DyXE1inlri0n60D2fEoUIripO9SY8Xi5K6Wv7fiLe6M2VFhy+s5wiNvJPTh4OQE0zMA/vVwbB09Ni1XKbLeka2mQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.51 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by mx.zohomail.com with SMTPS id 1599918053700448.8718555020589; Sat, 12 Sep 2020 06:40:53 -0700 (PDT) Received: by mail-wm1-f51.google.com with SMTP id e11so5901414wme.0 for ; Sat, 12 Sep 2020 06:40:53 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id u66sm10309144wmg.44.2020.09.12.06.40.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Sep 2020 06:40:51 -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=bXijLj9sePf1x7H7g7xUVbfkwlSyCDahYBi9izMEMaE=; b=mWclFZG+rQt0YMlTsFC8jd/YVGr7FvbSvnoJGD53SxaLLRwtL92z4UvC8ZgncgiqQl /RmxKRT5V4mDck53UMhiLxuiuFfxzGkerzl7hODRyh7AK8hfvpv8SOW5EX5i0nkaSZPR le+EqzYodO4pHTdJQUvnpCSl0UdkKmo4qypp7ndyZDbHrNE6rEcZLyuuTahT+E48trdr 6DPryFMlWPXeimEMbZy67QeRxlf1ShfYlnZ3BBkmivfYOk4A3fvjAtCULY1yO0xFABhT 6uLqaKoj//Kp/Mt285KpwXibBFJUGzxCrv5aeRLGozKUoGlpo8XGT64WuApvj8ydYrsV KRTQ== 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=bXijLj9sePf1x7H7g7xUVbfkwlSyCDahYBi9izMEMaE=; b=r4ky7UI39FGDvb2e55tKaxt44H/uBI13W+bSuAET5XoHqNdcshGfORd+KJ8KlCu3YF JuX7JvhJ0H6ptXiFmFcL9DRFJPembjqM/1zp8NpefUPO5GXTyCcBBtfXSep1fvwB4YB9 y0HUE5tuzPrVmENZHjzZCDpdrpkljVneyv5fw+hgVBS9WmFSrga6U1DhO2c+hRZ0piSL OGXcaIFyuyun9n3MJdi+uNdh7S1Gr+36/5ij+WPGN3JCqb8m1qKQ9lryH8s00SZawh1F LAYYrLZDt/r+hvwa2ekRvVlFgDcDb211GmAPkGJeSRyUXPzQqixcH+ZOAcMU5g6lm3Tg MbRQ== X-Gm-Message-State: AOAM531tuBoAtwiZd1aUYGsmnFD5GIrXArLL3yHYGKvgnQb8O+krIHsw 0BmpXKGMf22MfOEl0hQoNFc= X-Google-Smtp-Source: ABdhPJy5yafx0nDzTWUiRAMEeeulwNX5WS/71lbhS392aPjxTP323W1hxn0Qeat4Nw84k9DiCX+/MQ== X-Received: by 2002:a7b:cb4e:: with SMTP id v14mr6820406wmj.5.1599918051618; Sat, 12 Sep 2020 06:40: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: Andrew Jeffery , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Peter Maydell , Luc Michel , Andrzej Zaborowski , Eduardo Habkost , qemu-arm@nongnu.org, Richard Henderson Subject: [PATCH v6 5/7] hw/misc/mps2-fpgaio: Use the LED device Date: Sat, 12 Sep 2020 15:40:39 +0200 Message-Id: <20200912134041.946260-6-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200912134041.946260-1-f4bug@amsat.org> References: <20200912134041.946260-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- 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 991f5b731e8..513e3be6f13 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" @@ -35,6 +36,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 5c151fa3a83..0cecad45aad 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 5f3f6121bc9..908272e8593 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 Thu May 2 09:32:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.51 as permitted sender) client-ip=209.85.221.51; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f51.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.51 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1599918055; cv=none; d=zohomail.com; s=zohoarc; b=TA0wbLYsk7yQn85DaxJhwBqxwHoFtuqJ2PwgMuSryerxM6RWyQX48JpwT8gOFCSUfk9GbzzcY3lzDZsGuVO0CZfkXu6jtNTwqPkCdUcJnfPI1BLLYyuriteCIJ0X6JlVRB+5Bl6R1O/xW9ayw8EdOFP6w5mrv9Q8tlSVCOWMBYk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599918055; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5jonLkEs0bfAQb56MWErimOd7AbsJVnkd4i01BNhPLw=; b=NLjE+ZfL/KZrykQmPRP7dcxFtnxH8SAh3+yu7Pn2/gSHakTfcs1jHJ+SPRiof/m6LINjV9zkqQo6Ve7dyU4si+wbQcQDxxJnf3QrDvFDDTk3QCd5PO8gDMIb4xoq3zqkOYeFTLQYjyEZK1IYQmCKpV7FEKlHtxPqj9QyeGit24c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.51 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by mx.zohomail.com with SMTPS id 159991805555182.71648644288939; Sat, 12 Sep 2020 06:40:55 -0700 (PDT) Received: by mail-wr1-f51.google.com with SMTP id x14so14067555wrl.12 for ; Sat, 12 Sep 2020 06:40:54 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id u66sm10309144wmg.44.2020.09.12.06.40.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Sep 2020 06:40:52 -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=5jonLkEs0bfAQb56MWErimOd7AbsJVnkd4i01BNhPLw=; b=tI0P0bmrLxrX57L1IDZSIKcu56JJVbF+8DbAneZ+thrh2Jgayed6PtWT5lFu5teUpE OLZfA9qnpvno1CLUhnDVziuV0pdnfuJQ6k3TLktzVzXJEh0MHmcJrv/CVFLFjQiZiMvd dMg/w9eDE+CLJ2WdWt+S2X1XRawranqRlWDCVThag+l4TVbuAZkpP4+ackHe84nI9WJF Y1pc0hkg977W0JWaKODRz8+JPuTs/S+vSH9gK+CUfNtFzDU+M/5VDCzhNaFUO1ry8ydx qnvk2uivMAkBQss8CNZ+KBVy0eggPm1tWFWFM+qfZKMhZcEOSm3oN2v9kBfhWhpjoQGl I+LA== 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=5jonLkEs0bfAQb56MWErimOd7AbsJVnkd4i01BNhPLw=; b=YZCYXqgTQ5Fbk7VSWnj8H9AkG8BND/u1WB4ARUWvMe0vRDcWfgIajtQ3RXqSZG3bir CosKRDd0WYQjqQIGTRdpiuGKqFc7XKMl1ITJLdrO/W5hvES6QQj8kAZSuhCsD4n2QmcC wy6HU2oglaiKw2tml+SlGF2KeQEl1qA9SQQqQZBLSJgDbP/Io4v7zed9gH2p9EB6QBRS FC667uu78aiBkizVbITAK6A4CWZVRJXrcQ/o/+jVTHp7RvxLIvh8xU+TSh3ncKwkRhRy /UieeqHeZDVOnlyagRdJoPX/nzt3+5eM0NSrD9y2S9LXa0xrKrBC7kLL6ZrQmjVaPFRf l2EQ== X-Gm-Message-State: AOAM5338PgCUhqV8W/R6yfCNfAo1Us8JwGovwVfn5dJnXOFKNolUcYju JBZ9NJPJxljNQyh1EYmaMEY= X-Google-Smtp-Source: ABdhPJxhWP0JKUptI2SmQz/OShye0bsqZuRq+MbseRg1L5BdOEfDt+RogckwOpbUDq24vz/q8OwajA== X-Received: by 2002:a5d:4e0f:: with SMTP id p15mr6936109wrt.155.1599918053110; Sat, 12 Sep 2020 06:40:53 -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: Andrew Jeffery , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Peter Maydell , Luc Michel , Andrzej Zaborowski , Eduardo Habkost , qemu-arm@nongnu.org, Richard Henderson Subject: [PATCH v6 6/7] hw/misc/mps2-scc: Use the LED device Date: Sat, 12 Sep 2020 15:40:40 +0200 Message-Id: <20200912134041.946260-7-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200912134041.946260-1-f4bug@amsat.org> References: <20200912134041.946260-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- 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 445e268b1fd..0009479ae83 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" @@ -28,6 +29,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 0cecad45aad..7557a3e7b46 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 908272e8593..97f511aa58c 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 Thu May 2 09:32:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.128.66 as permitted sender) client-ip=209.85.128.66; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-f66.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.66 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=1599918056; cv=none; d=zohomail.com; s=zohoarc; b=ZrfZs6y3BGiWHrPzj05dx6EKTISzNvYEASQrzrpRPqOrbTL55i+TtRAC2Bdmvfu1ScWsxtxIILJVHTVqEXEcewqJp7OQ4ePo8nzcq1nwHCAFcIvyvBDsnK55nTbh8eowDzmiaZL7qMyExbNN72cjlAczZ991Re9rWATMKDDWlvc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599918056; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LRr5PGbbM0M9HoMOdGuvjP4Xsc2e6vYqTLWnU5FdlUg=; b=PZKq0XGuu2EkdFiFOdHW2LHkzhsFBdCbyEzoSn/y9fxJRIrQ5Hh9uzwsCzqNjeebuSdIUDiHKX5fengnQ9iOy2iWarvvW6ca0vs6eha2aQbXLieIFGSpvOs7HlltGDOBpUOHinFqGuYuw8OX8LBtkuVNsAN09MfNGhS6zhwJASk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.66 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by mx.zohomail.com with SMTPS id 1599918056608220.26023436928244; Sat, 12 Sep 2020 06:40:56 -0700 (PDT) Received: by mail-wm1-f66.google.com with SMTP id d4so1406021wmd.5 for ; Sat, 12 Sep 2020 06:40:55 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id u66sm10309144wmg.44.2020.09.12.06.40.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Sep 2020 06:40:54 -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=LRr5PGbbM0M9HoMOdGuvjP4Xsc2e6vYqTLWnU5FdlUg=; b=e2Vdrx6UVgfC+p7pfZ0wt5P3A1TjXmivQVWEjaHqZ55hDhWbDuBLzuH5TKVeSr6vDV eI9WYCFupAV3YqHTCjGvdJUhK7fp6BNJ9SZt4DnuGmoIUnJL4WL4Hcl1Xr1bXg9hIRUv E3V2Mq3XKj5DgWaqwVE494lrajBq2d7vk+CWxvnSYICyVOVb+iewiX7CLGBm/CgC/+37 l5ej2aGLv9uBhsjThoBp3HXK/6pkaJgPp1SdH94fwvtBBFIgxTsvK9EDLkFbcZFbNIbx SVkvXWaGMa0J5ZnjDu+SVrsIUG6yxd6gzAtE9qBMmh2aqVTzKZUNsDC1QjDYps6d9JWs TrIg== 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=LRr5PGbbM0M9HoMOdGuvjP4Xsc2e6vYqTLWnU5FdlUg=; b=aAvzvjObbh1iPrNjfjw3hHwmjyDpg8wDEMfB/gy0KVjUe/uhXbHwZsYOeR9hga9w5h bKl9M1QyMSKY4fxx8wlbs1roGjMRWHPPXFZtAuBbFVmpPcFoPReFPKIQLf67G3BElLX1 NDhhGQv/8gv7BFzLn9DZsgVB3vTP2BSVluOeIA+JvKzwv5i1W+TnUAEm+C1RiFAkzcHa gx8Hj1H2PILmV5TBLJ2aD0xYPtLwJfS73vhH+NXEyRwpDmV6SwJjArjZam6WottRra8R a7sOvWS4fCV3/mM6GojaTmi8+w680GvrhSwDGe8/aIL8coDlzaPhKFeVAB0Tgq2wQd9T kfVg== X-Gm-Message-State: AOAM532X6Nf6j9XdJptI9c0MRISGKVTeEQf4C1xcyyyFJEZLZd6fwWQl iF9Ki6BH3GSEqqzG+813+8E= X-Google-Smtp-Source: ABdhPJyG/yallnTCrunYD9mK592qQ9lp+5wRTy5EolEiYZSpKrlwVDDu/moUN9O/1I/YY/G5CFHfFw== X-Received: by 2002:a1c:a911:: with SMTP id s17mr7010141wme.77.1599918054610; Sat, 12 Sep 2020 06:40:54 -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: Andrew Jeffery , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini , Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Peter Maydell , Luc Michel , Andrzej Zaborowski , Eduardo Habkost , qemu-arm@nongnu.org, Richard Henderson Subject: [PATCH v6 7/7] hw/arm/tosa: Replace fprintf() calls by LED devices Date: Sat, 12 Sep 2020 15:40:41 +0200 Message-Id: <20200912134041.946260-8-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200912134041.946260-1-f4bug@amsat.org> References: <20200912134041.946260-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- 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 2ef6c7b2883..ca998f05232 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 @@ -83,26 +84,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) { @@ -114,7 +95,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 @@ -124,6 +104,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 @@ -145,14 +126,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 06ba1c355b1..bbcfa098ae2 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -150,6 +150,7 @@ config TOSA select ZAURUS # scoop select MICRODRIVE select PXA2XX + select LED =20 config SPITZ bool --=20 2.26.2