From nobody Tue Apr 30 23:03:23 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1599496383; cv=none; d=zohomail.com; s=zohoarc; b=n3TUjKNaRLrQZ/dN1DnOtrQFADusYuFYRcw3z73+OzuUwvqaEVsJ3G1t0M9711EopEKUSQWR4Kz5NS4Yy8HlNgejn4IlYeBi4BiHmIo+ShBAeXjudKzKf39BDHe2IzoSJnCpXzZ66DFZS65M01z0IAPezwfdFaL1qXmgWMy5f/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599496383; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DGrA/6H1/yD+065kC7Yi0CjoOdTH6U0Gf8J9d2c7Zr8=; b=CStdILAWLBAf7l9oiRds8k63/EH5nf9cvEP48o4RuG0yZGhKf2vg6WDYIXJgXaR0YKCe4amv30u9zmMAgmNXsWepbKDcgNS2RjwQK9Qfg3BoV9S9wq0AWkVDHsjjTZr6fuT7ljh0i7qOP+6haFX4biIRh/qt2BneoQcNuERmTgI= 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 Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) by mx.zohomail.com with SMTPS id 1599496383225779.4335310052165; Mon, 7 Sep 2020 09:33:03 -0700 (PDT) Received: by mail-ed1-f67.google.com with SMTP id l17so13270516edq.12 for ; Mon, 07 Sep 2020 09:33:02 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id u13sm15700199ejn.82.2020.09.07.09.32.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 09:33:00 -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=DGrA/6H1/yD+065kC7Yi0CjoOdTH6U0Gf8J9d2c7Zr8=; b=jyyWA58mBG0nBV5CKTZDmsL8QS8+FgvLaA5NX2G2uALBdYqxv4FR1pZlBup/ZO3Lk+ mOPTxzICLWml5aC+M6hFHcQw4syp/gDXBzw8TGogafxO4HMGsZB9q4Xa6AsCUArhjkK9 q9UA3yp1YfhRPx+sx5rnL1W32a+x1wYDQdgrrj2OT2aLOj00imJbrTRdazSG2aIZZK8D HoYt+HuAFawXmixpGvhRz9GmHQt6Ngk/wpBvKSXtv5ejeNVH3Zw82wmaGOJABCQpVsE8 qEawYMRYJ8Hr78fvcACmmkcjDQSxPDbunfW7RXluxij7FoVcVy0wp8gqGaKfmKYoP7Dz v/Eg== 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=DGrA/6H1/yD+065kC7Yi0CjoOdTH6U0Gf8J9d2c7Zr8=; b=OYOmru6+rtj4JZ4Nycucd00MURmXx61QkUVNYRfcKyEwLcfgwX/+Xc2m1nKnIDl6uM BUCqMLpCmK9RNYBv3aCx3OU1f1/fcfzN8qmNZSgbbk9u0087IGkWK23YnIbJE4KjjQ7X knRsEkT0V/LNApPmAA748KdfwEN5OTh7r64lbSLILXEfj1WHpsRbx/WNnuSw9ImGUAI7 tGIXc9CynTKbAlHn54i5OES8rXtqeyxBt9ptNSm8JCHOfwW5GJQeE5FpNcU8uNRCXJRQ txP0Csl4ha9m6s0PQpuc0+QNqieOp7w+j1sRb8HkCmgCHI4C3T2gA5LWJe4JLixo0OYE CxYQ== X-Gm-Message-State: AOAM531tW0iHzBGwaeL6/4SXg8YD4oqCp4tE8GQSI8qRKk/IojNJRME4 JNDIlPo+xl15niBKxt1nBdI= X-Google-Smtp-Source: ABdhPJzIIIzGnkUEp1Lrj2XfxmgmrDaJwkNx7jqbaBzcFHVM10sJQQSBzzsNvHUZpNHThgrYDgwXHA== X-Received: by 2002:a05:6402:1548:: with SMTP id p8mr23555148edx.65.1599496381227; Mon, 07 Sep 2020 09:33:01 -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: Andrzej Zaborowski , Peter Maydell , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Luc Michel , qemu-arm@nongnu.org, Andrew Jeffery , Joaquin de Andres , Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v4 1/8] hw/misc/led: Add a LED device Date: Mon, 7 Sep 2020 18:32:50 +0200 Message-Id: <20200907163257.46527-2-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200907163257.46527-1-f4bug@amsat.org> References: <20200907163257.46527-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. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Luc Michel --- include/hw/misc/led.h | 84 +++++++++++++++++++++++++ hw/misc/led.c | 142 ++++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 6 ++ hw/misc/Kconfig | 3 + hw/misc/meson.build | 1 + hw/misc/trace-events | 3 + 6 files changed, 239 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..1aaabbebafc --- /dev/null +++ b/include/hw/misc/led.h @@ -0,0 +1,84 @@ +/* + * 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 "hw/qdev-core.h" + +#define TYPE_LED "led" +#define LED(obj) OBJECT_CHECK(LEDState, (obj), TYPE_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; + +typedef struct LEDState { + /* Private */ + DeviceState parent_obj; + /* Public */ + + uint8_t intensity_percent; + + /* Properties */ + char *description; + char *color; +} LEDState; + +/** + * led_set_intensity: set the intensity of a LED device + * @s: the LED object + * @intensity: 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_intensity: set the state of a LED device + * @s: the LED object + * @is_on: 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 + * @parent: 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). + */ +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..f2140739b68 --- /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 *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 (led_color_name[i] && 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 b233da2a737..d040846b868 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 066752aa900..76c9ddb54fe 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -214,6 +214,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 Tue Apr 30 23:03:23 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1599496384; cv=none; d=zohomail.com; s=zohoarc; b=EiCF0/U2moFdOmF+YMsH+NUb+H0+5eH6sookFeUZ9BdFpjrb5xLvfcsvA5uGgFJgET68IKnxn40YAJJ2hwlstDsB0CeeBc6cjOjlcPQ09fTL5dQZx8aLJQpBABSjnfEHQSKQtoN6dNYJKL7N3QOa9lyLAve8p42f2TyRLtH5714= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599496384; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VNbcpVtna5bpU7n81cix+fetWM20QpCF3F6nhCiudhQ=; b=CvuQYp/dYAwpoH2aoHzce3S5HND9fJqcoN+pNy2k0AAdYQUAgaVr8/hwL44kZwZHX/yw/dA7AP2Hbr78+4IJsOP9uxRGTVZaXnmEfwfw5p5pwTgR0VGp51n0KL5qkU9nowxt0EKY0gO+VCVYGgGsMNX6EcPNRS5OFIFlxE0HI9k= 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 Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by mx.zohomail.com with SMTPS id 1599496384860885.3989967204217; Mon, 7 Sep 2020 09:33:04 -0700 (PDT) Received: by mail-ej1-f65.google.com with SMTP id a26so18971568ejc.2 for ; Mon, 07 Sep 2020 09:33:04 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id u13sm15700199ejn.82.2020.09.07.09.33.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 09:33:02 -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=VNbcpVtna5bpU7n81cix+fetWM20QpCF3F6nhCiudhQ=; b=Lsra9HzP9MY8fC6amVNSnK9RIttSVRIDNAo7ZVenbXPeC+d7FLhru2Larq7F0cwxH9 7A+1x5dtEHr7d7X8o+moA6ydLEfoLQqdWvDjl9Kfr2Jf0WEA08VsQbSXsul5VP4f4WBz 5wO80IO5hMpD7iGTf+HkodI05Ua3cKKD5Ta3eG+HyCX7ZPo+sb7xQjR/lGRUsyP1sgCn RaA+8spjY4Xc1aE1pY6zEFS+6NZZP76V8o4bOMdzvnXgltI7KtodTz4wJxEDAg0oxqUp UzH0WDeBNBtX7N3HRP7NJTPa7H6EKVF2rMQGib4ZiGq0PUA7CyKtjr8HIMXhjymB6io2 9UWg== 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=VNbcpVtna5bpU7n81cix+fetWM20QpCF3F6nhCiudhQ=; b=OQjOBXFfGSEGbt/dE5Lni4i+QS3fQU/PlctDGoU5BziHdWRGAoG8IAlB+H0rGsrYpt jKbtXX3fzIgIxIiBzbujtcdgs+jyVfJa+EazuSYdjLXZ4W9woyqkPgIosT6ACa8zkoFu EkuDpxYB62+HWVIFiZK3GeVW+njAGvv5YmySe5D8HyJAdTTC20neyySC7fbNmyogMI3d fiyOtoFL3jNZemgkORRwMszYuT+5yBP/Wxq4HtloerI2/1d3iO269+zLHgwLaT1YcWgD VJxKKhLS3a6VFCmOLVfJGV9wlNufUAyiM7sKtbTgj7cu/LKxivXF9jUx/9raliFqljQN SDsQ== X-Gm-Message-State: AOAM533KMwZzklypN7YUKAbh7IyU1Dkfviw/GTjiPfBwqnSa1+8j4uH0 E/SehZnpYJo3xh4Y3GXiBtM= X-Google-Smtp-Source: ABdhPJxGLaRMjJjguE+3rJHPw8QpT0NRuDthkCZFOR88+Gn0lmfnBM2KpBc+w/J/zRInktHy4AP+GA== X-Received: by 2002:a17:906:2552:: with SMTP id j18mr21262657ejb.476.1599496382901; Mon, 07 Sep 2020 09:33: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: Andrzej Zaborowski , Peter Maydell , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Luc Michel , qemu-arm@nongnu.org, Andrew Jeffery , Joaquin de Andres , Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost Subject: [PATCH v4 2/8] hw/misc/led: Allow connecting from GPIO output Date: Mon, 7 Sep 2020 18:32:51 +0200 Message-Id: <20200907163257.46527-3-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200907163257.46527-1-f4bug@amsat.org> References: <20200907163257.46527-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 --- include/hw/misc/led.h | 8 ++++++++ include/hw/qdev-core.h | 8 ++++++++ hw/misc/led.c | 17 ++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/include/hw/misc/led.h b/include/hw/misc/led.h index 1aaabbebafc..c8dd6da74d5 100644 --- a/include/hw/misc/led.h +++ b/include/hw/misc/led.h @@ -38,10 +38,16 @@ typedef struct LEDState { /* Public */ =20 uint8_t intensity_percent; + qemu_irq irq; =20 /* Properties */ char *description; char *color; + /* + * When used with GPIO, the intensity at reset is related + * to the GPIO polarity. + */ + bool inverted_polarity; } LEDState; =20 /** @@ -71,6 +77,7 @@ void led_set_state(LEDState *s, bool is_emitting); /** * led_create_simple: Create and realize a LED device * @parent: the parent object + * @gpio_polarity: GPIO polarity * @color: color of the LED * @description: description of the LED (optional) * @@ -78,6 +85,7 @@ void led_set_state(LEDState *s, bool is_emitting); * drop the reference to it (the device is realized). */ 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 ea3f73a282d..846354736a5 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -424,6 +424,14 @@ 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 + */ +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 f2140739b68..1acade1d592 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->inverted_polarity); +} + static void led_reset(DeviceState *dev) { LEDState *s =3D LED(dev); =20 - led_set_state(s, false); + led_set_state(s, s->inverted_polarity); } =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("polarity-inverted", LEDState, inverted_polarity, fal= se), 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, "polarity-inverted", + gpio_polarity =3D=3D GPIO_POLARITY_ACTIVE_LOW); qdev_prop_set_string(dev, "color", led_color_name[color]); if (!description) { static unsigned undescribed_led_id; --=20 2.26.2 From nobody Tue Apr 30 23:03:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.208.41 as permitted sender) client-ip=209.85.208.41; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ed1-f41.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.208.41 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=1599496386; cv=none; d=zohomail.com; s=zohoarc; b=UAE0BYNbZR34swUEVAHMcNVtRbQNFfpvkazywhtIxZacoUoVWAqBkG8uRm8baaip6hQg3mfr+KY9pAN/uqPjENA4rURYRyQ6bGEG7t4VMzEF85mSBnNVaNasgjDYRxMKDCBF9i3Qw5/zIAwnQ4chQpJg1ea6EFaOI72gslbhIPI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599496386; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sOTWIKCT6VDFv2Z2z68Ud6vgTWqu6BKF5mHpas4qUIU=; b=gqY2O5bqC62zSXm68a6U2KMIAjviaUtaXv4pDoWNky3wEkg99r6FhqGCI/fPxn0tDLAKD6f83RzbnvZyN3rliSHYH206kSmL9/P4AcLQ5BUGyskL/yOPg+Qb0su5QBXfgX/Yb5/nGohzJrErCSw4lH2+RXiXGEkAFhfFcXNAMhg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.208.41 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) by mx.zohomail.com with SMTPS id 1599496386372114.34147339040089; Mon, 7 Sep 2020 09:33:06 -0700 (PDT) Received: by mail-ed1-f41.google.com with SMTP id b12so13286849edz.11 for ; Mon, 07 Sep 2020 09:33:05 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id u13sm15700199ejn.82.2020.09.07.09.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 09:33:03 -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=sOTWIKCT6VDFv2Z2z68Ud6vgTWqu6BKF5mHpas4qUIU=; b=CbNlWh0SZ+7iSW1+FYz4wkXR13QN3P64ZIb9mGTZ45QuJKP8BzwzHJWcUZ4opDAS+U NPwfnLRggsDeRGkYoETvHFcOISfCCoZEBl+m+F2F4mhClWL1W/PD5k5C1JukQNptuduA tQYQrZiO1+J2GdIJssDIepQ8IXYIGxQp/bQ/kOcAVQj7UzI7873cVIxKWzS6H6JJMr3A EIGAyzN7jkWU3F93RLTnvnKHR4JYudYeEVDsMDW+esIf/UaVOF8/qwDCf6g0x5jA086X KDLkQl6FTCHaGXnVaaqSBu6CGskE+VSvlpwu2B6tB0ppiVXB+JvGr12EHMXcectt4ETm SBGQ== 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=sOTWIKCT6VDFv2Z2z68Ud6vgTWqu6BKF5mHpas4qUIU=; b=f405QVhG+XXDgeCoOUXaevNKBcngHEdgVRdIpDozwE41J4Tu+y2u7VKeyvwwZPwqai 8QfBNsOg6Gha1+PY1E1Sq9c0Hvky9mLa/yb5r/rQDmlxTYkgVMI4/MTX4CCOrl3wtg9v FThOxR1SprymSEzmxgIxm/S1UeOqlrbaWG9dmJysVIsTS8CPGuzKDu4FqhuqowgKOv3X UpBcHbbbCSamzNSQYgWKvxL5ps3rCIzKU8cZvnt3gxT3UDKbW81OSWkI/35jDA9BGPsW QO9veSWhOS96udtpUbIsAy1Byj1pV1FOX0hRSGVSR3fMmrkkdh8/uTNPrNMvoBFGTIsA lWIg== X-Gm-Message-State: AOAM5302Cvbb98cyq40kJl47I1AsmgsHMHQVEChQVB5rnFb5KbIt1Cqp JT43VFg+wNcvtAjFp/1BLEw= X-Google-Smtp-Source: ABdhPJz4mZwYDnh5f9SkSMuj18wRVfof8pdYAQR5sxNMR440kQguG89aeMXab6/H9yyTddV3KMHFew== X-Received: by 2002:aa7:dbd9:: with SMTP id v25mr23489525edt.78.1599496384529; Mon, 07 Sep 2020 09:33:04 -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: Andrzej Zaborowski , Peter Maydell , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Luc Michel , qemu-arm@nongnu.org, Andrew Jeffery , Joaquin de Andres , Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH v4 3/8] hw/misc/led: Emit a trace event when LED intensity has changed Date: Mon, 7 Sep 2020 18:32:52 +0200 Message-Id: <20200907163257.46527-4-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200907163257.46527-1-f4bug@amsat.org> References: <20200907163257.46527-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 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 1acade1d592..b7e9b1465bb 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 76c9ddb54fe..89d15f05f9a 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -216,6 +216,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 Tue Apr 30 23:03:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.208.68 as permitted sender) client-ip=209.85.208.68; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ed1-f68.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.208.68 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1599496388; cv=none; d=zohomail.com; s=zohoarc; b=FzWV8kTZ/wNvP7uoEL62lBsbFvA1sCLUsNzluKku59uUSWf97zsFfHbyfLVGK6DJlodOIFEx3+U130v3qkTVtcW6kKMmBlqzMBrs/9/aD1qsyGCrsBlIZARE8zcVjzggJ2GskuDNc+klnACC2e1sWdlsSeIjuirR5XdKAzwY+oA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599496388; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pr3IdxupnoTag8g+l9d/z4aY7eG0d/P7ZaZKT2cQb14=; b=cResHlu01/QnfBK7eBE/ZuOYQKSwg3OnFS9FOrNQfhEVFRXSv3Mn0A1dSNR+mQSbBcyLyAWeifPq8D097v4/muLs2RCMIkOgptpV14UeAflEiMpYze4G3IlB6JUvRh4kY5/B1WEgdbOInBL//HJJNLyA2q00hDhOz9vpFwcxY6I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.208.68 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by mx.zohomail.com with SMTPS id 1599496388417207.82306829361664; Mon, 7 Sep 2020 09:33:08 -0700 (PDT) Received: by mail-ed1-f68.google.com with SMTP id q21so13356108edv.1 for ; Mon, 07 Sep 2020 09:33:07 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id u13sm15700199ejn.82.2020.09.07.09.33.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 09:33:05 -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=pr3IdxupnoTag8g+l9d/z4aY7eG0d/P7ZaZKT2cQb14=; b=tSXeiDOvHKsgXQGnF2c5ZkjZL1FPCrWs6AKIXfNbiIW8OFg3ChzJYIwf3fDZyNURNX 1ERSEPxjHXTjWF05PJFRz64nI8EEHVV0C8LM+c1a8zSOcyYnC+K3z9HraFl7+L0L3Jz9 9ce+JbTBrusEN1Lle+Toqx/kucDmc8l24NP+6REZQ+y9PyZfsPPnKXJWuefw1K22CkTF cNQ/dlOxfgq/PLNzsVfBn1DEjESy2wDGeMR9GlwZLYw9Go2RGimnOUG49pEaPn8D6geW YQv3UWG+CQJClLwSbZdwLpO9JyTlt0HH3p0fOYBm4vCMhsynYxUrTWbveA6cvtI6gpmZ qBzw== 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=pr3IdxupnoTag8g+l9d/z4aY7eG0d/P7ZaZKT2cQb14=; b=t6uM/wLbQCrLQ9ZDrgSywNjDEplEvoyFonHXbxs2JqL0s4sTRmNNxlZthmnKBRzuKZ 9tm44x8zkNElHqNHcze/YtH8vlsGvHVj4sNiICk7Qgik1PvnWroGWbfuSVuHRtt+1qO1 NlZiD0f8wXrofrLyUJKiOvnmGFdfrWCGLptS/sPTNUyP05drw9tVXjAeJsy+QS1nYwyj JFtAcv/VNmIfjsaNlsOddUWIwtCC9P8IleujCqQKq9mhxQMloksAefGAbSmZkWItBWPA J0yN0RfZuuDhEYvT3t6p2Tzq/1AHhaYg4n3KgeQm/L6cRy3mrdcvj+FZ4bPVcnSNDSN5 IMdQ== X-Gm-Message-State: AOAM5300CHiIOKUl+iPXDkuKbWU8HdIlaLNRdxf2htoM/sO4uxottm2X amIlX5svyiLSO4Zt3wt0f5KDYWhJ+rU= X-Google-Smtp-Source: ABdhPJzgF4A2LH6+tLU2pOKb6e91t41o8McNQebV7qFRxUtojodsrIC6NKYX3l7tPv118u7F6ylIuw== X-Received: by 2002:a50:be82:: with SMTP id b2mr23115522edk.303.1599496386488; Mon, 07 Sep 2020 09:33:06 -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: Andrzej Zaborowski , Peter Maydell , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Luc Michel , qemu-arm@nongnu.org, Andrew Jeffery , Joaquin de Andres , Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH v4 4/8] hw/arm/aspeed: Add the 3 front LEDs drived by the PCA9552 #1 Date: Mon, 7 Sep 2020 18:32:53 +0200 Message-Id: <20200907163257.46527-5-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200907163257.46527-1-f4bug@amsat.org> References: <20200907163257.46527-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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- 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 Tue Apr 30 23:03:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.218.46 as permitted sender) client-ip=209.85.218.46; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ej1-f46.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.218.46 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1599496390; cv=none; d=zohomail.com; s=zohoarc; b=WPq9PJ2tEvo0361Z6SYC56mA08frm5l+jQByZeY5jZfuYCb0zhgWxWGG1uZK2LV7yBgTzDM7KyCyzFDhM0hjtn/G9GV6UY25ThQa9fnlfitFPwYZGGcV6tIej3XJnjfPRBz+/RUBnM8wAt16TJaurzYoI+gVonp9OnOVgo9h5T4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599496390; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vnMbp0E6IauzdwSblFJxUFoyT1SAl8asRcn4brlYdgU=; b=WdjPnDKn4+g/YtyjaGJ0i4DXV/Vog4iecmMe2kgkUXW429WV/LC6vH3IikEKEuFek6rd9dBv7pY/twsMwzSaApE77BeVjZbV8aHj4WNQjJKC6lKIONlYsHLbZoybgsLQSAEwHoAQnmxTQGcNiet9w4HZHgmA/Zp2XM+v79kXLSI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.218.46 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) by mx.zohomail.com with SMTPS id 1599496389998939.0033690277223; Mon, 7 Sep 2020 09:33:09 -0700 (PDT) Received: by mail-ej1-f46.google.com with SMTP id j11so19007718ejk.0 for ; Mon, 07 Sep 2020 09:33:09 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id u13sm15700199ejn.82.2020.09.07.09.33.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 09:33: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=vnMbp0E6IauzdwSblFJxUFoyT1SAl8asRcn4brlYdgU=; b=k2BHvMi9S3ZAnUEn5yqffbSu5ai+2rZWZdTvTWsfL6IdnuFMhN26ye83MMRu68ZlpM AzaBUTGXEO57eDn5cmoRoF+vwhJA8WjBcNldlvLsZqli2iaygO2894n1B1PaPLrRseZq zS3j7rzl17JV6WnH0wgORo+CdENqP9+/MQZIsRDIUpOTQ2TWwvBkUjF5JDIYkBdT9icR Gezb8AIJHG1nVzXQgL2H+Tg7NilhLUAb+kvgGqgrKtXs1fzHPLgGhZzHCMveGv/JtXHZ cpOzKOJ3NO2c9vjpfiVABJc2xayIflcPTUH061ZDgiqAZN4RU8mU621PzQzdUYdD6iH6 BA9g== 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=vnMbp0E6IauzdwSblFJxUFoyT1SAl8asRcn4brlYdgU=; b=SHiGAll/Xp8WbnVQhU+EXGjcsFxufFZTNS8aPPYfesZJ2rgW/94Cw9yX+uJv1dif7L +z10twV63wbAPAkNnRk9xYdLMyxIv2WCqYYJkE5pfkQaMr5IsCLFGv+PFVBfjSDhOnhX EejH2+DYz7bq+L8h7ba4X+mr5hnPmUde0cvurJl+EK6Q0Mo3CeMHuy4Y1cPvqNMPunj4 dTg//QE0ZF1fOwXDG/9Q8moQWLquTO9yLc0+TZcLfd0GDXB0ltbUps9kQUGRX5/Kb4mT mzVyH+uc+gz9qbBFmHb+xePKy+UNfKwu9uElt4/jpBaAS9407duI+w7tYd3pKErdl5FC EJzA== X-Gm-Message-State: AOAM532loXTX3wqxzbQZ/k5T3v5DQcG7m0dVz0UCZ1vuLtzKXSSmJyOx z18znmaA7DJFJKiLDWQSHY0= X-Google-Smtp-Source: ABdhPJypUMK1mA6HEhGv+otI8NhoJNDDucjRKbQj4JzqT/jRcwpuzFzJNZzAiH2qK4dpWu3ChaKNAQ== X-Received: by 2002:a17:906:a1d7:: with SMTP id bx23mr22318070ejb.273.1599496387962; Mon, 07 Sep 2020 09:33:07 -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: Andrzej Zaborowski , Peter Maydell , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Luc Michel , qemu-arm@nongnu.org, Andrew Jeffery , Joaquin de Andres , Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v4 5/8] hw/misc/mps2-fpgaio: Use the LED device Date: Mon, 7 Sep 2020 18:32:54 +0200 Message-Id: <20200907163257.46527-6-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200907163257.46527-1-f4bug@amsat.org> References: <20200907163257.46527-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 remplaces the 'mps2_fpgaio_leds' trace events by the generic 'led_set_intensity' event. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/misc/mps2-fpgaio.h | 2 ++ hw/misc/mps2-fpgaio.c | 19 ++++++++++++++----- hw/misc/Kconfig | 1 + hw/misc/trace-events | 1 - 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/hw/misc/mps2-fpgaio.h b/include/hw/misc/mps2-fpgaio.h index 69e265cd4b2..901880cc3a7 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" =20 #define TYPE_MPS2_FPGAIO "mps2-fpgaio" #define MPS2_FPGAIO(obj) OBJECT_CHECK(MPS2FPGAIO, (obj), TYPE_MPS2_FPGAIO) @@ -32,6 +33,7 @@ typedef struct { =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..86ca78eb235 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); @@ -251,6 +249,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 +307,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 89d15f05f9a..43b9e0cf250 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -93,7 +93,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 Tue Apr 30 23:03:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.208.68 as permitted sender) client-ip=209.85.208.68; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ed1-f68.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.208.68 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1599496391; cv=none; d=zohomail.com; s=zohoarc; b=GI0TlLm1ETu56qSXU+CM+WFg9sX41FFstSPttovL3AA7EOZhj1u0+xaEw+pSikKwf1jKcrjltonwbbvxVRmqQ24RZCZFsmHQ+RLaTFKGFur3O/ADc1oe+/FTnYkPKMoRASaKgYiC6h/JKGDr+eHW7rgP13d5uCzXiXeqjKMizWM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599496391; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jBgL1iKIvz4jH+dRa8U6fT1B6oJw6/SF3dkJ8j+0tYI=; b=DgCVXJLr4KdEj/0HwrGr4MTQsTwnpBgTu5x6/JUY/voABifJRQ6Sdjx7RyXBvXUP1I/KsdADgzBgfI+j9Qsmyx1IBShzau17eDo/fVtaV0/BnZgKdapENYOu87d81lduh5t2mhC9guu4sQ7AWWX35WrSoWrVqoC6zgiM/A/2KZE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.208.68 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by mx.zohomail.com with SMTPS id 1599496391424739.6169104113225; Mon, 7 Sep 2020 09:33:11 -0700 (PDT) Received: by mail-ed1-f68.google.com with SMTP id b12so13287026edz.11 for ; Mon, 07 Sep 2020 09:33:10 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id u13sm15700199ejn.82.2020.09.07.09.33.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 09:33:08 -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=jBgL1iKIvz4jH+dRa8U6fT1B6oJw6/SF3dkJ8j+0tYI=; b=NGwwOK8a+fHGjLxYQTX0miQrbkb8sWxiahi18i6/0l6gF2OCge51BPuralxFjDtOwG WCR670KtplUUFKsjcCQr8P1sU9i7rgyNA5lEb+6IT9gi6Dj+I2Tx350khN+lPnGT+9jm C3oI9QO/O1+Ly8LcPWfLjnwig/6OuLuH0aKntPyUxpIY9q2Fssck494TxIb9sPAyt+Ov sOTMz4y2wWmUh6W3mLJH4TujsmMJTDU8b8GqG5wEuVteNt1JAtP6rTk9P3yTnvqbd2cj WsDaiEDYYWivElWw5n4lmyvTcSlCVkPvEGNJ4GUxVgPa3Qhu4QrajWR5xmGR7XFNses5 sPWg== 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=jBgL1iKIvz4jH+dRa8U6fT1B6oJw6/SF3dkJ8j+0tYI=; b=fepUXc8UIwg2I2eZf5XRRszDH4wqtBRiFjJg4EAKARajQpTR6SQuqagn4/STRyv1gD EhB8CFlHpja9qy4UtJ8KP2GFSAyTk+aZfPeKP7MMUAmMy1+RMMpz2f77KZegnqdfdGtD V3yJ4zZD0E3e+4fwWwZaBdS8wOjrTRQoacXVS93PNTreL1VrBF/1mrVfStiplMey9dGn z7xsECz6m5k1Bu4hzE+lEunjNl3Rw2542FM3x4DZbZ1gCT4sy3rcRrUNxzvWJSscMuWH Kik1iVLmcqkoBjuTmqaR85jPP/tN1GDrFoeLm5vXyFy913JglFoOfdUh55xsE420AAwg ukmQ== X-Gm-Message-State: AOAM533N9yh2G6JF0Hsrtxw7o5E7Vr6oWC1C/eeh+f0QADl2TlLBS6w+ hiWrTnbNIX5X6b5RTHXBJyo= X-Google-Smtp-Source: ABdhPJzLqAShOBauj9CSuC2lWda9KUiMdypw8ZqnFRsq/c1VE1GLiZkhjn3SOr7dgMJjd13xiI7RlQ== X-Received: by 2002:a05:6402:b68:: with SMTP id cb8mr4902112edb.350.1599496389494; Mon, 07 Sep 2020 09:33:09 -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: Andrzej Zaborowski , Peter Maydell , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Luc Michel , qemu-arm@nongnu.org, Andrew Jeffery , Joaquin de Andres , Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v4 6/8] hw/misc/mps2-scc: Use the LED device Date: Mon, 7 Sep 2020 18:32:55 +0200 Message-Id: <20200907163257.46527-7-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200907163257.46527-1-f4bug@amsat.org> References: <20200907163257.46527-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 remplaces the 'mps2_scc_leds' trace events by the generic 'led_set_intensity' event. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- https://youtu.be/l9kD70uPchk?t=3D288 --- include/hw/misc/mps2-scc.h | 2 ++ hw/misc/mps2-scc.c | 25 ++++++++++++++----------- hw/misc/Kconfig | 1 + hw/misc/trace-events | 1 - 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/include/hw/misc/mps2-scc.h b/include/hw/misc/mps2-scc.h index 7045473788b..8542f384227 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" =20 #define TYPE_MPS2_SCC "mps2-scc" #define MPS2_SCC(obj) OBJECT_CHECK(MPS2SCC, (obj), TYPE_MPS2_SCC) @@ -25,6 +26,7 @@ typedef struct { =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..745505b849d 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; @@ -245,10 +239,19 @@ static void mps2_scc_init(Object *obj) =20 memory_region_init_io(&s->iomem, obj, &mps2_scc_ops, s, "mps2-scc", 0x= 1000); sysbus_init_mmio(sbd, &s->iomem); + } =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 43b9e0cf250..a620a358feb 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -85,7 +85,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 Tue Apr 30 23:03:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.218.67 as permitted sender) client-ip=209.85.218.67; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-ej1-f67.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.218.67 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1599496392; cv=none; d=zohomail.com; s=zohoarc; b=kM5phULMcMrGezoO1An3ccfCf9bfaU38nnjf4u25dZj3A4jRgUP/gIwGyQx0pp7pqixAYeSFAfc5kcbFZKGjmk7aJ4m6buoGR4JPP70PTm+gwwXos0eowbileSUpmuEtqFpDvPnlbay8Li3AAeYPFwR0lmb1WyokDXa0mvTjZ2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599496392; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jeiRRdPErRrtK9Gj9+R/jotAsL7dELgR1Q5VvxS+mnE=; b=FI3+28BjJbSn2jiV+HnBJ5r9thBU/YQ5baZv6RnYq6cZLQlfBRu51GvppRhBQmMc46oU5nlKdMFkgXEMTZMf5q3xQHLcSlY99yNIlXw0SE1CNUENlaCgsX3NocfckevMIChC6PYUAISfkzhIR6X711jq8i5sfWdjaem01Af84FU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.218.67 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by mx.zohomail.com with SMTPS id 1599496392988571.7074304996164; Mon, 7 Sep 2020 09:33:12 -0700 (PDT) Received: by mail-ej1-f67.google.com with SMTP id a26so18972026ejc.2 for ; Mon, 07 Sep 2020 09:33:12 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id u13sm15700199ejn.82.2020.09.07.09.33.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 09:33:10 -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=jeiRRdPErRrtK9Gj9+R/jotAsL7dELgR1Q5VvxS+mnE=; b=qb6K7+ipyUmvsw9nZ2i/KdjQlDvSPjt8fLFlI/E5oQueKAPHguVSYrHQ2lWVhqoHbu TkSorb82zKPXbUUZK2aglcaDmoZjNDC1odPUktC5hkQellTK7KkiDu5N/xS4C3djRgRi GubSxwDFo9kq3xRxZSxFU4XbiDSJRlw+nhuO+f7RiwpQtv/W36s3TVsaV8L103yhUK4/ 8ycwcj5Qawe8EcjJMs1UTjqemfoEbBJBXoLapRcMiZxD74ENYOUpJlkXgn0QfeB+Ke9c Rw0P177KQfM1Q6JcsA/UkDyr9yTBLkyfAbx4gwJeMyGf5OPBiXb5w1Q8DNLYkub+3CbZ /cDQ== 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=jeiRRdPErRrtK9Gj9+R/jotAsL7dELgR1Q5VvxS+mnE=; b=RubOF6hecTHeZlNabQTXsiL4toIRwieVxLfrM0WwHHdDHGJJVuhkzrkVqISTy4T0Lc yTnTCVTUbhU1bhiTZZLwJPXhmuL/w03/PQFnxJPVEcLliAtNYw7cMJs/1HZQ55p05/x7 UC1PvrtA2ZkbQxQen6v9npN1uwZldIpQHdJVVVQY+dHMw0220mtDBHOhCjTkKcab+Gy8 8XkjwiroYaAqDyuQAHGIZ1tjYjzgoXpESYRdxaP0F2EFRCK2IlcPUnKOLRzxqJz/0TSn RzbIRzwZgETQXmjQ5S0q8WK15iPxLtu7MN8UGGVhM7Oed358RgPNhbPdfDrE5xdJetPO doPQ== X-Gm-Message-State: AOAM530K5hTOx28qazpjLDbagRWqhdFAn1RWiH9eMtGDgo41w0J6FoJ1 zqggJ/EOsTyk1bZ0gzGfscI= X-Google-Smtp-Source: ABdhPJxif1S8WYd//dNJ5p0OU4D5QlgtDNoRmnZGFvKW7jsYMD3vA96jY2tc7MMFWZkQlwDI0h0L6Q== X-Received: by 2002:a17:906:63c9:: with SMTP id u9mr18426715ejk.82.1599496391020; Mon, 07 Sep 2020 09:33:11 -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: Andrzej Zaborowski , Peter Maydell , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Luc Michel , qemu-arm@nongnu.org, Andrew Jeffery , Joaquin de Andres , Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v4 7/8] hw/arm/tosa: Replace fprintf() calls by LED devices Date: Mon, 7 Sep 2020 18:32:56 +0200 Message-Id: <20200907163257.46527-8-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200907163257.46527-1-f4bug@amsat.org> References: <20200907163257.46527-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. 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 90eef1f14dd..f23651fd775 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" =20 #define TOSA_RAM 0x04000000 @@ -81,26 +82,6 @@ typedef struct TosaMiscGPIOState { SysBusDevice parent_obj; } TosaMiscGPIOState; =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 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 From nobody Tue Apr 30 23:03:23 2024 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=1599496394; cv=none; d=zohomail.com; s=zohoarc; b=gMMbTLdIskoirAAeIS1WLNY3eg0vtJe6Xo+ttK6IRim8Lk6o0cebtyZasbNCaP2OyDs/5Ux/5T8YaWnETcskUuP0hDaKEYSXg1+a9ybnQ89qsjT1e8W6GcxaPzSzJEyEEa0NnCk0L7Dqrd6ZlluUfW8W+o41ODMLew75MrDKj3U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599496394; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=39vGPecl12q7amHLWo3+1dhvTYjWZnqSb7DebE6TMyI=; b=Uw8M4eGySjN6zEyLDFxZ3QZXGHl0CBH/2KyMQls8oJ4Uroxm0jaWEQ3Kvn3MPOqhvHDXavFA08W45sQTuOFMk3nMmfSSN7dnTabpWMS90rczr35PuCGcEBvv1tjiqKPKa9uc0GKju6CxofDlXqTGlgfO+fXedEy5zTJCjW2wAYQ= 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 1599496394426604.9521843474038; Mon, 7 Sep 2020 09:33:14 -0700 (PDT) Received: by mail-ej1-f68.google.com with SMTP id nw23so18925209ejb.4 for ; Mon, 07 Sep 2020 09:33:13 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id u13sm15700199ejn.82.2020.09.07.09.33.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 09:33:11 -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=39vGPecl12q7amHLWo3+1dhvTYjWZnqSb7DebE6TMyI=; b=c4ORQXt5p3mIsNygpyg8uGyXK2YdhgONePrYj9xNLEyo2y+IlL/DhZrcsR9aKI1A62 XpNHdReeRbZl+tnopgaVfG5JApL2ygDwLgrWz39hlj1MLRhjmeFxduRenhCB8enxLyi9 axXPgq9VWtqSfj52BAOxDmC8bnKLuir64hTNSMtP5inmjEQI1gdzHlCZby3SB6+RP94N 1ZUIwcx4Omyk6ZT87EABhnREynU00JGJlFvZ1YUxr7yXHC8rP+fYdznvHxoH2kwwVZhX Ywcvt2nX/b1dq6DoFAuOf1e/TRUdIb8bC4RjQk7q7hog4rvnrLKZoTUWlKmBWeXmxBC8 FIKg== 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=39vGPecl12q7amHLWo3+1dhvTYjWZnqSb7DebE6TMyI=; b=PMsQBBs8y0PNqchfQ4HUFWsPmVjzHTODG6dNNBdpKjI7fswFuCMp3Rm+h8oiEVxVa3 o8zX/H5mOWeyVEsnaplMttZojaojiD2o23RgQjA2NhTVawGVwBn+nZO+U2dbWBNqgB0u 92JXT2SomHZr5dxLviEaokaWyVFycW/QTdKtnYRdoqzOFPC6KPZ6VcVW7LeZ2wSyXqbc 1IznhkfXAyjnLJ/T1u3FYGvQpwkkZQNmD60rsSwj+4W9wxCNTRKn0cg6IvumJ2N1qAhx qmE38swiKxTqof9nbEPBV6TEc3a9b1GrDATBwwIaJap59Ro2WCNHrTYtIDfGgtk6w05J L3Tg== X-Gm-Message-State: AOAM531AjTGUVHmsciMCFCfkszFg0OWm5is/MoCx02LQ2oi0MVIEa/Xz IUVhYNcMjJui/AIslTc6U9E= X-Google-Smtp-Source: ABdhPJxt1MMTkOVhjFJfnCIZZ7Uhj7zI8VlZiYK9WpwlPX97EA2DNAe9Tcvb3pTJLs8imJricYxiQA== X-Received: by 2002:a17:906:8d8:: with SMTP id o24mr21240332eje.384.1599496392492; Mon, 07 Sep 2020 09:33:12 -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: Andrzej Zaborowski , Peter Maydell , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Luc Michel , qemu-arm@nongnu.org, Andrew Jeffery , Joaquin de Andres , Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster Subject: [RFC PATCH v4 8/8] hw/arm/tosa: Make TYPE_TOSA_MISC_GPIO a plain QDev Date: Mon, 7 Sep 2020 18:32:57 +0200 Message-Id: <20200907163257.46527-9-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200907163257.46527-1-f4bug@amsat.org> References: <20200907163257.46527-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) TYPE_TOSA_MISC_GPIO doesn't need to be a SysBus device, make it a plain QDev. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- RFC because having to pass MachineState and call object_property_add_child() simply makes things more complex... but it seems to cleaner QOM design. Cc: Markus Armbruster --- hw/arm/tosa.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/hw/arm/tosa.c b/hw/arm/tosa.c index f23651fd775..524d5fcd10b 100644 --- a/hw/arm/tosa.c +++ b/hw/arm/tosa.c @@ -79,7 +79,7 @@ static void tosa_microdrive_attach(PXA2xxState *cpu) OBJECT_CHECK(TosaMiscGPIOState, (obj), TYPE_TOSA_MISC_GPIO) =20 typedef struct TosaMiscGPIOState { - SysBusDevice parent_obj; + DeviceState parent_obj; } TosaMiscGPIOState; =20 static void tosa_reset(void *opaque, int line, int level) @@ -96,7 +96,7 @@ static void tosa_misc_gpio_init(Object *obj) qdev_init_gpio_in_named(dev, tosa_reset, "reset", 1); } =20 -static void tosa_gpio_setup(PXA2xxState *cpu, +static void tosa_gpio_setup(MachineState *machine, PXA2xxState *cpu, DeviceState *scp0, DeviceState *scp1, TC6393xbState *tmio) @@ -104,7 +104,10 @@ static void tosa_gpio_setup(PXA2xxState *cpu, DeviceState *misc_gpio; LEDState *led[4]; =20 - misc_gpio =3D sysbus_create_simple(TYPE_TOSA_MISC_GPIO, -1, NULL); + misc_gpio =3D qdev_new(TYPE_TOSA_MISC_GPIO); + object_property_add_child(OBJECT(machine), "pcb-container", + OBJECT(misc_gpio)); + qdev_realize_and_unref(misc_gpio, NULL, &error_fatal); =20 /* MMC/SD host */ pxa2xx_mmci_handlers(cpu->mmc, @@ -253,7 +256,7 @@ static void tosa_init(MachineState *machine) scp0 =3D sysbus_create_simple("scoop", 0x08800000, NULL); scp1 =3D sysbus_create_simple("scoop", 0x14800040, NULL); =20 - tosa_gpio_setup(mpu, scp0, scp1, tmio); + tosa_gpio_setup(machine, mpu, scp0, scp1, tmio); =20 tosa_microdrive_attach(mpu); =20 @@ -307,7 +310,7 @@ static const TypeInfo tosa_ssp_info =3D { =20 static const TypeInfo tosa_misc_gpio_info =3D { .name =3D TYPE_TOSA_MISC_GPIO, - .parent =3D TYPE_SYS_BUS_DEVICE, + .parent =3D TYPE_DEVICE, .instance_size =3D sizeof(TosaMiscGPIOState), .instance_init =3D tosa_misc_gpio_init, /* --=20 2.26.2