From patchwork Thu Sep 10 20:54:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 305644 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0013C43461 for ; Thu, 10 Sep 2020 20:57:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 464EE2080A for ; Thu, 10 Sep 2020 20:57:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PwCbOOwg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 464EE2080A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kGTd1-0000ut-7I for qemu-devel@archiver.kernel.org; Thu, 10 Sep 2020 16:57:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41044) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kGTaX-0004CE-F0; Thu, 10 Sep 2020 16:54:37 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:53646) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kGTaV-0000Gu-6U; Thu, 10 Sep 2020 16:54:37 -0400 Received: by mail-wm1-x343.google.com with SMTP id x23so1846451wmi.3; Thu, 10 Sep 2020 13:54:34 -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=XbPWkZDQFZTFzxM3NgUg96m1QQb5/GeK1JAiZFw/yJE=; b=PwCbOOwgLA3bV5IsJZ6O7Bbz2TLSuo5WGgS7qZrn1RBl4HaBFSGWnv3BLfFHi+SNYU uyc0x5n+B8BVc462mBkmUkJ+d9v2fJpeG0S7fty1Ku8Wy0tWZ+6unrULo85aCxBs7fe4 yO05iORfsLEOx56MNQLyao2J2rLMIcsSJhLWlYkSkXk9gQLhTYoCyGJDDRWzGPNcQfx7 HxilxwnpN8Yf5BWz4xeVW5VkFP23Cryr5pU/HK14iFZcv9hfyo5a7U/IPcatuyU0nVXy S7IVc70wleIf/zAMxUQ3IxdpByUssbLWTbS8oAraRTWGglCmygL20QToRKgVnAeQvZoB aq5A== 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=XbPWkZDQFZTFzxM3NgUg96m1QQb5/GeK1JAiZFw/yJE=; b=I5neFzXpFUf8ILss1jR7DOWNdKKWgdoEf4XSq4qz549Y/7HcMYZKByfPp3nmF+X1oA Zu6wTpEflu9+/5phnKA2rCBsElQCDYETtTBsU0MAwifBzqGgcO/EcdZnhgiiC7eNHyb2 vdpgHj5ZJX4eYgwSrBF0wLsPpKnrJ1d23/z/LBcwpI62Rl32NYYYXvSA66dx/u4l5sYm yrpgWCNKcYtc0ll1JluJAoUtPlx6xMJ3HaIhMTAOXggKP5B2TDakZKOpzii2lOc+r0l1 Kdnl94PdOAgyOV3qTf1o5gOpKcfBYc4PlpnvmHhtV6Or+3eTzS2+mPqsYkjJ8SvBWiOq lreg== X-Gm-Message-State: AOAM530pXMKzQSTwcDBr+xwcOEMic1qnPfH9zmYl83ectBtPaeQHqE+3 37EtEWWwjQGMaSsgWOTwwUsMYrboBVA= X-Google-Smtp-Source: ABdhPJwtpnyML1BeKNfWoP/xSX1u7osToDbLggSFDwAfOOMm7se4BpobqA0e7Isq8AHfLJPKWXkLNQ== X-Received: by 2002:a1c:dec2:: with SMTP id v185mr1838030wmg.1.1599771272927; Thu, 10 Sep 2020 13:54:32 -0700 (PDT) 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 t1sm5089317wmi.16.2020.09.10.13.54.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 13:54:32 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v5 1/7] hw/misc/led: Add a LED device Date: Thu, 10 Sep 2020 22:54:23 +0200 Message-Id: <20200910205429.727766-2-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200910205429.727766-1-f4bug@amsat.org> References: <20200910205429.727766-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::343; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-x343.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Daniel_P=2E_Berran?= =?utf-8?b?Z8Op?= , Eduardo Habkost , Andrew Jeffery , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= , qemu-arm@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goate?= =?utf-8?q?r?= , Paolo Bonzini , Luc Michel , Joel Stanley Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é --- 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..f5afaa34bfb --- /dev/null +++ b/include/hw/misc/led.h @@ -0,0 +1,84 @@ +/* + * QEMU single LED device + * + * Copyright (C) 2020 Philippe Mathieu-Daudé + * + * 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_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). + */ +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..89acd9acbb7 --- /dev/null +++ b/hw/misc/led.c @@ -0,0 +1,142 @@ +/* + * QEMU single LED device + * + * Copyright (C) 2020 Philippe Mathieu-Daudé + * + * 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[] = { + [LED_COLOR_VIOLET] = "violet", + [LED_COLOR_BLUE] = "blue", + [LED_COLOR_CYAN] = "cyan", + [LED_COLOR_GREEN] = "green", + [LED_COLOR_AMBER] = "amber", + [LED_COLOR_ORANGE] = "orange", + [LED_COLOR_RED] = "red", +}; + +static bool led_color_name_is_valid(const char *color_name) +{ + for (size_t i = 0; i < ARRAY_SIZE(led_color_name); i++) { + if (strcmp(color_name, led_color_name[i]) == 0) { + return true; + } + } + return false; +} + +void led_set_intensity(LEDState *s, unsigned intensity_percent) +{ + if (intensity_percent > LED_INTENSITY_PERCENT_MAX) { + intensity_percent = LED_INTENSITY_PERCENT_MAX; + } + trace_led_set_intensity(s->description, s->color, intensity_percent); + s->intensity_percent = 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 = LED(dev); + + led_set_state(s, false); +} + +static const VMStateDescription vmstate_led = { + .name = TYPE_LED, + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT8(intensity_percent, LEDState), + VMSTATE_END_OF_LIST() + } +}; + +static void led_realize(DeviceState *dev, Error **errp) +{ + LEDState *s = LED(dev); + + if (s->color == 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 == NULL) { + s->description = g_strdup("n/a"); + } +} + +static Property led_properties[] = { + 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 = DEVICE_CLASS(klass); + + dc->desc = "LED"; + dc->vmsd = &vmstate_led; + dc->reset = led_reset; + dc->realize = led_realize; + set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); + device_class_set_props(dc, led_properties); +} + +static const TypeInfo led_info = { + .name = TYPE_LED, + .parent = TYPE_DEVICE, + .instance_size = sizeof(LEDState), + .class_init = 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 = NULL; + DeviceState *dev; + + dev = qdev_new(TYPE_LED); + qdev_prop_set_string(dev, "color", led_color_name[color]); + if (!description) { + static unsigned undescribed_led_id; + name = g_strdup_printf("undescribed-led-#%u", undescribed_led_id++); + } else { + qdev_prop_set_string(dev, "description", description); + name = g_ascii_strdown(description, -1); + name = 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 7d0a5e91e4f..ca7f47aa936 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1951,6 +1951,12 @@ F: docs/specs/vmgenid.txt F: tests/qtest/vmgenid-test.c F: stubs/vmgenid.c +LED +M: Philippe Mathieu-Daudé +S: Maintained +F: include/hw/misc/led.h +F: hw/misc/led.c + Unimplemented device M: Peter Maydell R: Philippe Mathieu-Daudé 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 +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('tmp105.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')) # 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 status, 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" +# led.c +led_set_intensity(const char *color, const char *desc, uint8_t intensity_percent) "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_state, unsigned current_state) "%s GPIO id:%u status: %u -> %u" From patchwork Thu Sep 10 20:54:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 273974 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6C58C43461 for ; Thu, 10 Sep 2020 20:55:52 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3D454221E3 for ; Thu, 10 Sep 2020 20:55:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="n4t4oGP6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3D454221E3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kGTbj-0006O8-6I for qemu-devel@archiver.kernel.org; Thu, 10 Sep 2020 16:55:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41048) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kGTaX-0004CM-Pg; Thu, 10 Sep 2020 16:54:37 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:42163) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kGTaW-0000H6-As; Thu, 10 Sep 2020 16:54:37 -0400 Received: by mail-wr1-x441.google.com with SMTP id c18so8629690wrm.9; Thu, 10 Sep 2020 13:54:35 -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=Q0lfFRL4xWLEBHVRUO7uZKpVUCkRWQqd0DscmUXOlik=; b=n4t4oGP65oBHUYzE2xK0F74MlbEbRT5IAFeK833QZzdZ8LCW8GBjoZwleGAZqgbieN jYNDKs+Td7Q1MghsoZu4BAjSCI21ev9quK6FkVmPetufVnsdhALR0eoh47mVbJi/kcK+ po5rSGPA/Gz8wZggnqAzc58xrNK8K+HWSwBMqmU+zcxVG3wSZ7DTaAUbwApTouEwsIy8 ZQ0rp85u5rNbSl6uUOYjQRF3VpShEJsypvMRfodgbq3rx48a8+Y7zHEdMibFEDlggc5k jstX7Km6cbPCq7lETo7Ypkth4c3DxGK7WAaST/V9Lv2p03Bs/3XbtA4i/c7N0PQ60gvy n/hg== 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=Q0lfFRL4xWLEBHVRUO7uZKpVUCkRWQqd0DscmUXOlik=; b=Dvzg6iacQMQqtbSl3O/ZuntqVVtHP8aggMrD9bvg7vfwgcpkUyVSKU+QWYjclkf/xO 4bwp95Bw57yQvk5G/0GDYUWSu0m1L5WpVhP2LcO3k94TuFT16YBrUnP/HTe4mxCUU3Il cknQ5HPwxHi5v9as59iBSmWX46O08iLJY7kJvgCPqTTgOx1HOLo4dXqFeGVjg56zFHhe NYYNEM7xd2l3AZa5thL0g5IgRKa0c+RE7jmzkp6WAw2cX0U6le1n3dJSJnk4kse2q/zj WNxfgegXQOCpbYErIN+xK6mjFSoKKdQhJh65jXee1PkFQ+1sEpwtug1IM9LWIBDSbcK6 aKsg== X-Gm-Message-State: AOAM533R5sN6vriJV8W87IzjF2+ivX/cCmzcc5/S9cnyyAkuFtAaejEW jFvvodDWZ+IPb2qfhqQyLwPKpXdzrHY= X-Google-Smtp-Source: ABdhPJx1/klY/b7lHzVg/lHiWf4QfI1RfKvlSI3b28vXALBDwk6fyH5xFOOT+TW2AjASN0LbLXh2LQ== X-Received: by 2002:adf:dd0e:: with SMTP id a14mr10840273wrm.151.1599771274236; Thu, 10 Sep 2020 13:54:34 -0700 (PDT) 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 t1sm5089317wmi.16.2020.09.10.13.54.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 13:54:33 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v5 2/7] hw/misc/led: Allow connecting from GPIO output Date: Thu, 10 Sep 2020 22:54:24 +0200 Message-Id: <20200910205429.727766-3-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200910205429.727766-1-f4bug@amsat.org> References: <20200910205429.727766-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::441; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Daniel_P=2E_Berran?= =?utf-8?b?Z8Op?= , Eduardo Habkost , Andrew Jeffery , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= , qemu-arm@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goate?= =?utf-8?q?r?= , Paolo Bonzini , Luc Michel , Joel Stanley Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é --- 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 f5afaa34bfb..71c9b8c59bf 100644 --- a/include/hw/misc/led.h +++ b/include/hw/misc/led.h @@ -38,10 +38,16 @@ typedef struct LEDState { /* Public */ uint8_t intensity_percent; + qemu_irq irq; /* Properties */ char *description; char *color; + /* + * When used with GPIO, the intensity at reset is related + * to the GPIO polarity. + */ + bool inverted_polarity; } LEDState; /** @@ -71,6 +77,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) * @@ -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); 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 *hotplug_dev, void qdev_machine_creation_done(void); bool qdev_machine_modified(void); +/** + * 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 89acd9acbb7..3ef4f5e0469 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" #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); } +static void led_set_state_gpio_handler(void *opaque, int line, int new_state) +{ + LEDState *s = LED(opaque); + + assert(line == 0); + led_set_state(s, !!new_state != s->inverted_polarity); +} + static void led_reset(DeviceState *dev) { LEDState *s = LED(dev); - led_set_state(s, false); + led_set_state(s, s->inverted_polarity); } static const VMStateDescription vmstate_led = { @@ -84,11 +93,14 @@ static void led_realize(DeviceState *dev, Error **errp) if (s->description == NULL) { s->description = g_strdup("n/a"); } + + qdev_init_gpio_in(DEVICE(s), led_set_state_gpio_handler, 1); } static Property led_properties[] = { DEFINE_PROP_STRING("color", LEDState, color), DEFINE_PROP_STRING("description", LEDState, description), + DEFINE_PROP_BOOL("polarity-inverted", LEDState, inverted_polarity, false), DEFINE_PROP_END_OF_LIST(), }; @@ -119,6 +131,7 @@ static void led_register_types(void) type_init(led_register_types) 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; dev = qdev_new(TYPE_LED); + qdev_prop_set_bit(dev, "polarity-inverted", + gpio_polarity == GPIO_POLARITY_ACTIVE_LOW); qdev_prop_set_string(dev, "color", led_color_name[color]); if (!description) { static unsigned undescribed_led_id; From patchwork Thu Sep 10 20:54:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 273972 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D17B1C43461 for ; Thu, 10 Sep 2020 20:57:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 53CDA21D7E for ; Thu, 10 Sep 2020 20:57:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="upX18BBU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 53CDA21D7E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:48492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kGTdB-0001Id-Bd for qemu-devel@archiver.kernel.org; Thu, 10 Sep 2020 16:57:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41058) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kGTaY-0004DY-Pw; Thu, 10 Sep 2020 16:54:38 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:40432) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kGTaX-0000HI-BQ; Thu, 10 Sep 2020 16:54:38 -0400 Received: by mail-wr1-x431.google.com with SMTP id j2so8648428wrx.7; Thu, 10 Sep 2020 13:54:36 -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=Pg2UbiPnEyj3JIOQp/7lnXV/UdSauRuubalG7cq91s0=; b=upX18BBU9qj81TIw224hWd7f9RodAdsuGcLJF8YW8hkxK/1nX1QocqrHGG08utTLXb c+ahbIOqRY6ci46wv5yx10szetuUy9cwJEZIQCyd2gD/sc/esJCRqzl1Q0zbi/pfatX2 rYyP+zidhMPc3gJyCXj9x4B7j20w/CwTWi2l/gk7+ZAmBf38gTAYyjl+pgclpuNDpE4F iHY/ReqDZDTJkh8GirSxLq3nGpSFW7WoVluLlAuC8ezn57ClopgsL+iGZTYnd2Zd+/YW qPabM5r8vhZWGpdyH5kNZWhaqnHDqrGMZZM6LCIZrR4pN8wKvbgF5ki8+0uuJIny7p58 96Yw== 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=Pg2UbiPnEyj3JIOQp/7lnXV/UdSauRuubalG7cq91s0=; b=WWvLeYphv3/jSP5OAzlrFcfi7kBIEzZahE8lHmteay9MgN91U7ttQBDr8KoUVmrfOn 0ulYSCCmYXGozvDT/kIe0YuMUo03L93ekMXiVzB3eFHkeUnBihsK/HlbkolQOmnBIFxy V1mn23wV14WBV5xrTanVtUyw7vUcLm+6kRBYjK8OmEt/xQABje3zXao03iXwvt6whOZN 0TsSs0Z07fMy3vnadNZMYKE3iwyB556hUal4RrERL3L6DPeRoTzD7YVaATlxqDYsRYLK nLJNqnn115aucE9qa/8dSdpxK2xK1xM7QPOugGyDcj3QgxXxvU1KDh2O5iDouuclfd/S 57Zw== X-Gm-Message-State: AOAM533/htCiWPDINEA335EhRZd142PeIB3coC/K2nTMrDESqofGZeOd fYfyQWPGlmmuPw+8MOTkxBz1W+CF/3o= X-Google-Smtp-Source: ABdhPJxtI5kY0fz0HXzHsDqTwqgijyyUagdhcuYMVPv8h6iRNy4t+RQq+G/25ecdRgBI419gf+JiKQ== X-Received: by 2002:a5d:62c2:: with SMTP id o2mr10657829wrv.418.1599771275494; Thu, 10 Sep 2020 13:54:35 -0700 (PDT) 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 t1sm5089317wmi.16.2020.09.10.13.54.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 13:54:34 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v5 3/7] hw/misc/led: Emit a trace event when LED intensity has changed Date: Thu, 10 Sep 2020 22:54:25 +0200 Message-Id: <20200910205429.727766-4-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200910205429.727766-1-f4bug@amsat.org> References: <20200910205429.727766-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x431.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Daniel_P=2E_Berran?= =?utf-8?b?Z8Op?= , Eduardo Habkost , Andrew Jeffery , Richard Henderson , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= , Paolo Bonzini , Luc Michel , Joel Stanley Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Track the LED intensity, and emit a trace event when it changes. Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daudé --- 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 3ef4f5e0469..ebe1fa45b1e 100644 --- a/hw/misc/led.c +++ b/hw/misc/led.c @@ -41,6 +41,10 @@ void led_set_intensity(LEDState *s, unsigned intensity_percent) intensity_percent = LED_INTENSITY_PERCENT_MAX; } trace_led_set_intensity(s->description, s->color, intensity_percent); + if (intensity_percent != s->intensity_percent) { + trace_led_change_intensity(s->description, s->color, + s->intensity_percent, intensity_percent); + } s->intensity_percent = intensity_percent; } 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 # led.c led_set_intensity(const char *color, const char *desc, uint8_t intensity_percent) "LED desc:'%s' color:%s intensity: %u%%" +led_change_intensity(const char *color, const char *desc, uint8_t old_intensity_percent, uint8_t new_intensity_percent) "LED desc:'%s' color:%s intensity %u%% -> %u%%" # pca9552.c pca955x_gpio_status(const char *description, const char *buf) "%s GPIOs 0-15 [%s]" From patchwork Thu Sep 10 20:54:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 305645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55D3DC43461 for ; Thu, 10 Sep 2020 20:56:02 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B65182080A for ; Thu, 10 Sep 2020 20:56:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XMJ8XoJv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B65182080A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kGTbs-0006pP-N5 for qemu-devel@archiver.kernel.org; Thu, 10 Sep 2020 16:56:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41070) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kGTaa-0004Fk-IX; Thu, 10 Sep 2020 16:54:40 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:34949) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kGTaY-0000HX-J6; Thu, 10 Sep 2020 16:54:40 -0400 Received: by mail-wr1-x443.google.com with SMTP id e16so8678264wrm.2; Thu, 10 Sep 2020 13:54:37 -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=XMJ8XoJvNLl+l/3ThwTUrJhBW/ats7GMT8TS3AGtudRW2cEklhfmlxFBeAgDr3Pzh9 X0RV2MTmz5xq1c6r195QWwKzW334K3xv2WtBCkGn0RbzJ4D4pWirWo/rV9aORCpZtOWI a9cSmkR8QNpZdfBz3pMDdY5sewQe2X+Xhnceqmcy+lE4wtx7X4h2VZQY7KUteac7hGdJ Skhxzq5CdUvVBJVP6uPjF4bzG6KlWXv50HNLeWsPcF89rH3viTwSI2sXhp/77fpnJCdj GOk8qX1qBsJxDwv/mAGQ1fLTUTgBcLGz67ePVf+L7z/3gxow7lr+g7YKhLrFZyKm8oJl xUGA== 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=Nq7/LcOSqAubuCHVCQ02ZsvgJ4OM4WzkqNPv4+WIbZTmBQIAy0G/L6qSDz4x7sHI1Q 3m2BDUof9WjldBYtYuob1aTbHlGOAHT7fQA+ktKsZpLkM8SLxBqbPId+HQpQ7lXZ+2U1 B6JoKKpu1afuk45OGGGyCCKjwKzR8Qyx8YcFPHG6ai4VW/1FuVdIsnTDFzDjfMuoIjsl NkOgoHGx7YabYz/5xGeGKIenHfVLQ4sYzv0RqL0utwYjK/Z0UQNTzV6CUMdO8xz4nApa f66eljfFHf+ixTvzJC596BlFAHfdpakb+RP9snPDkbjUqj3YPnisTA61eV566l3ghfeG MJjg== X-Gm-Message-State: AOAM531Z+mSpt8uKMr06a7/1p1yxGo0NdNnDPT1dVq2oPa5SMhzyB1kU bihwF1P8GcPsmyAwwzKzj2N8cAH7+7A= X-Google-Smtp-Source: ABdhPJyYEhLk0L+LnTwtisIRLRf3X/QyUVGGGaYFyN+gRx0E9MwrlbIDeDtZpAWA5R0JrOolmp4QGg== X-Received: by 2002:adf:8b48:: with SMTP id v8mr10930209wra.21.1599771276760; Thu, 10 Sep 2020 13:54:36 -0700 (PDT) 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 t1sm5089317wmi.16.2020.09.10.13.54.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 13:54:36 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v5 4/7] hw/arm/aspeed: Add the 3 front LEDs drived by the PCA9552 #1 Date: Thu, 10 Sep 2020 22:54:26 +0200 Message-Id: <20200910205429.727766-5-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200910205429.727766-1-f4bug@amsat.org> References: <20200910205429.727766-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::443; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x443.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Daniel_P=2E_Berran?= =?utf-8?b?Z8Op?= , Eduardo Habkost , Andrew Jeffery , Richard Henderson , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= , Paolo Bonzini , Luc Michel , Joel Stanley Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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:green intensity 0% -> 100% 1592693373.997632:led_change_intensity LED desc:'front-power-3' color:green 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:green intensity 100% -> 0% 1592693500.312041:led_change_intensity LED desc:'front-power-3' color:green intensity 0% -> 100% 1592693500.821254:led_change_intensity LED desc:'front-power-3' color:green intensity 100% -> 0% 1592693501.331517:led_change_intensity LED desc:'front-power-3' color:green intensity 0% -> 100% 1592693501.841367:led_change_intensity LED desc:'front-power-3' color:green intensity 100% -> 0% 1592693502.350839:led_change_intensity LED desc:'front-power-3' color:green intensity 0% -> 100% 1592693502.861134:led_change_intensity LED desc:'front-power-3' color:green intensity 100% -> 0% 1592693503.371090:led_change_intensity LED desc:'front-power-3' color:green 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é --- 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) static void witherspoon_bmc_i2c_init(AspeedMachineState *bmc) { + static const struct { + unsigned gpio_id; + LEDColor color; + const char *description; + bool gpio_polarity; + } pca1_leds[] = { + {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 = &bmc->soc; uint8_t *eeprom_buf = g_malloc0(8 * 1024); DeviceState *dev; + LEDState *led; /* Bus 3: TODO bmp280@77 */ /* Bus 3: TODO max31785@52 */ @@ -534,6 +546,14 @@ static void witherspoon_bmc_i2c_init(AspeedMachineState *bmc) aspeed_i2c_get_bus(&soc->i2c, 3), &error_fatal); + for (size_t i = 0; i < ARRAY_SIZE(pca1_leds); i++) { + led = 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", 0x4c); i2c_slave_create_simple(aspeed_i2c_get_bus(&soc->i2c, 5), "tmp423", 0x4c); 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 config MPS2 bool From patchwork Thu Sep 10 20:54:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 273971 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10CC6C2D0A7 for ; Thu, 10 Sep 2020 20:59:10 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A74A521D7E for ; Thu, 10 Sep 2020 20:59:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XV/kzY7R" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A74A521D7E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54486 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kGTeu-0003l5-7q for qemu-devel@archiver.kernel.org; Thu, 10 Sep 2020 16:59:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41086) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kGTac-0004H2-6T; Thu, 10 Sep 2020 16:54:42 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:46814) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kGTaZ-0000Hk-W0; Thu, 10 Sep 2020 16:54:41 -0400 Received: by mail-wr1-x42f.google.com with SMTP id o5so8593428wrn.13; Thu, 10 Sep 2020 13:54:39 -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=XV/kzY7Rl5zm+9oYL6HBoDbfOFK8NMcdGh4lEQSoNJ2nc/om3QgskwbeKSCivkQ5V/ GlbhDfh3bm4wDe2y/0L+bxwg1UXcTW6zuzOMnsMRKkqPEy2f8b5pkymq4BMlGXeGTEUO MhftaWIPF9kfezdWA5biVEyHUOw2demUTgXQWxzWR1d3SH6a6UMCnUozVt8K6vzwE+ec 2eENy/AkaNNpxvuWoLN+Cpk2sWBh0L12vRFryRh0OHxCH7pCGQb9Dg/BY3UxVF2Rz+Y9 ZzNP1GXUiNWbnjh9g8IwhvBlvarlEXGn9/lzvlGIU5ds3fZgix6JnSMukccCPakV/34T LvCQ== 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=mDdKO/Tl0B7pH3/mjFQ/riXC1EE+rRrkXZ/+HNlyAdqbxZObQ35+lt+OKGhhxh4AQh GOoD6TKc7Ndqa5rn1HWugeBAUELvcwqxXxLogUjXTV4+PE7r8ArzTGAmjohBhlakjJN7 qg5Je7IIfFGAVqsfzOPSr3horvl8p10uLVMQreMHE2yp5TpYte6pLrh4QOlKpJLi8kDY RjAgP5YdjjYCBfciidRWSQ4WpvbTQPRBxoy2aMpzby76XbS29aGoGZbPOQj2MlpR6aYc BH9Ahi9/luG/FL3jrNFKm5lw8jEGTUQcwIZq92z0hEtbDiiIvgrl0xHcX6T42+BexdpX 1rag== X-Gm-Message-State: AOAM532W7Ls3r4hz8G2yWMMRzUnujAbnKoMQObyHEWpw8tOaqEoHYUAK O3/JRUgbHxit7hRliQgXBck+FJOJkCo= X-Google-Smtp-Source: ABdhPJyIXE/lNORdgK9VDBE4yzTW77L8ihNEThRs6429JUOKxxEr6ywM216QfBQjM8MrgEYGDuxOVg== X-Received: by 2002:adf:f58b:: with SMTP id f11mr10910155wro.250.1599771278004; Thu, 10 Sep 2020 13:54:38 -0700 (PDT) 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 t1sm5089317wmi.16.2020.09.10.13.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 13:54:37 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v5 5/7] hw/misc/mps2-fpgaio: Use the LED device Date: Thu, 10 Sep 2020 22:54:27 +0200 Message-Id: <20200910205429.727766-6-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200910205429.727766-1-f4bug@amsat.org> References: <20200910205429.727766-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x42f.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Daniel_P=2E_Berran?= =?utf-8?b?Z8Op?= , Eduardo Habkost , Andrew Jeffery , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= , qemu-arm@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goate?= =?utf-8?q?r?= , Paolo Bonzini , Luc Michel , Joel Stanley Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é Reviewed-by: Richard Henderson --- 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 #include "hw/sysbus.h" +#include "hw/misc/led.h" #define TYPE_MPS2_FPGAIO "mps2-fpgaio" #define MPS2_FPGAIO(obj) OBJECT_CHECK(MPS2FPGAIO, (obj), TYPE_MPS2_FPGAIO) @@ -32,6 +33,7 @@ typedef struct { /*< public >*/ MemoryRegion iomem; + LEDState *led[2]; 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" @@ -176,12 +177,9 @@ static void mps2_fpgaio_write(void *opaque, hwaddr offset, uint64_t value, 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 event. - */ - trace_mps2_fpgaio_leds(value & 0x02 ? '*' : '.', - value & 0x01 ? '*' : '.'); s->led0 = 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); } +static void mps2_fpgaio_realize(DeviceState *dev, Error **errp) +{ + MPS2FPGAIO *s = MPS2_FPGAIO(dev); + + s->led[0] = led_create_simple(OBJECT(dev), GPIO_POLARITY_ACTIVE_HIGH, + LED_COLOR_GREEN, "USERLED0"); + s->led[1] = 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' function */ @@ -299,6 +307,7 @@ static void mps2_fpgaio_class_init(ObjectClass *klass, void *data) DeviceClass *dc = DEVICE_CLASS(klass); dc->vmsd = &mps2_fpgaio_vmstate; + dc->realize = mps2_fpgaio_realize; dc->reset = 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 config MPS2_FPGAIO bool + select LED 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, uint32_t value) "MPS2 SCC mps2_fpgaio_read(uint64_t offset, uint64_t data, unsigned size) "MPS2 FPGAIO read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" mps2_fpgaio_write(uint64_t offset, uint64_t data, unsigned size) "MPS2 FPGAIO 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" # msf2-sysreg.c msf2_sysreg_write(uint64_t offset, uint32_t val, uint32_t prev) "msf2-sysreg write: addr 0x%08" PRIx64 " data 0x%" PRIx32 " prev 0x%" PRIx32 From patchwork Thu Sep 10 20:54:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 273973 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79F30C43461 for ; Thu, 10 Sep 2020 20:56:05 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 020A62080A for ; Thu, 10 Sep 2020 20:56:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="svLfx+sk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 020A62080A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kGTbv-0006vj-Ts for qemu-devel@archiver.kernel.org; Thu, 10 Sep 2020 16:56:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41098) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kGTad-0004K6-8t; Thu, 10 Sep 2020 16:54:43 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:40425) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kGTab-0000Hu-GZ; Thu, 10 Sep 2020 16:54:42 -0400 Received: by mail-wr1-x429.google.com with SMTP id j2so8648802wrx.7; Thu, 10 Sep 2020 13:54:40 -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=svLfx+sk71ilf1v7mWwgPQgvz9Qd0vt5/dpJ0UrIuGsT7baiAv6AaII2q9v/Bc2ziN ra9Rv1ExUCMKzbvSHQMisdWXjYNITHFwZ4meCebEaOiJwlwBtiGz06jhiCeVSPxzgLut LRKcwSuUbWkl0M1ETT+5a+pFx1HojMoVC7CbJV6zQt/4Wmbb78TlfvZ/cB9tZEeh6EWH M8CXjS2qoeIZ6hX1RMyz2eFWNpGe7yIG4jdH/R3+4we0+OlQCveaA1SxZdAcY527artu JK4wcVb71UXyAslT946KDkUGKDxiDMa/3ubCiXkPB3THJ6znEgJQpj6cBQsBr4djMiNw qt4g== 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=T0AFyfwJf2cmyd+MJZclugiHDhhc+TEb97srrpdxigtgZIZ3biIjI6I7LmnNT8lQDg XBGBiqTwEG4W808pOyO1seHGe3RjFxsxV+DnkTHRH9UW416fyey8VBj2LOTZhwmE5Q4h wqmivY3j2pg62Qo4NOaEXUBmqhsRgmrA2qgz6CNI0g2V/MP1DsqAtbl8SYSX2ta3CLUw X34r3ShiVQ4aMddKVfLVjUIaSHG0G04cr33tCBsy7zjK6T0hMcxInEAxdI9OzeK+wIpJ B1maUtFnES420dEjuUHqbcobJzgbHPYDMFDBsXDhl+ObY+JPWAYM8H5FGJPzPzpGVmCe KhmQ== X-Gm-Message-State: AOAM530QoHFVaxUSnb+RI3d/vh0P1vZwJpnqioAS8w/UzRjpo7XhF2F0 NXBG/Z+pQRhzYn4g1iyC4X/eGExx2B4= X-Google-Smtp-Source: ABdhPJwv4fKzCEYQmsDnkP5x2gyr6A31QscgE8a8Jy+2REJYvQuVfT6rfomLk2OBmZECRyJgl/YIUQ== X-Received: by 2002:a5d:5042:: with SMTP id h2mr10980380wrt.409.1599771279223; Thu, 10 Sep 2020 13:54:39 -0700 (PDT) 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 t1sm5089317wmi.16.2020.09.10.13.54.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 13:54:38 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v5 6/7] hw/misc/mps2-scc: Use the LED device Date: Thu, 10 Sep 2020 22:54:28 +0200 Message-Id: <20200910205429.727766-7-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200910205429.727766-1-f4bug@amsat.org> References: <20200910205429.727766-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x429.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Daniel_P=2E_Berran?= =?utf-8?b?Z8Op?= , Eduardo Habkost , Andrew Jeffery , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= , qemu-arm@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goate?= =?utf-8?q?r?= , Paolo Bonzini , Luc Michel , Joel Stanley Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é --- https://youtu.be/l9kD70uPchk?t=288 --- 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 #include "hw/sysbus.h" +#include "hw/misc/led.h" #define TYPE_MPS2_SCC "mps2-scc" #define MPS2_SCC(obj) OBJECT_CHECK(MPS2SCC, (obj), TYPE_MPS2_SCC) @@ -25,6 +26,7 @@ typedef struct { /*< public >*/ MemoryRegion iomem; + LEDState *led[8]; 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" REG32(CFG0, 0) @@ -152,18 +154,10 @@ static void mps2_scc_write(void *opaque, hwaddr offset, uint64_t value, s->cfg0 = 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 event. - */ - trace_mps2_scc_leds(value & 0x80 ? '*' : '.', - value & 0x40 ? '*' : '.', - value & 0x20 ? '*' : '.', - value & 0x10 ? '*' : '.', - value & 0x08 ? '*' : '.', - value & 0x04 ? '*' : '.', - value & 0x02 ? '*' : '.', - value & 0x01 ? '*' : '.'); s->cfg1 = value; + for (size_t i = 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 = value; @@ -245,10 +239,19 @@ static void mps2_scc_init(Object *obj) memory_region_init_io(&s->iomem, obj, &mps2_scc_ops, s, "mps2-scc", 0x1000); sysbus_init_mmio(sbd, &s->iomem); + } static void mps2_scc_realize(DeviceState *dev, Error **errp) { + MPS2SCC *s = MPS2_SCC(dev); + + for (size_t i = 0; i < ARRAY_SIZE(s->led); i++) { + char *name = g_strdup_printf("SCC LED%zu", i); + s->led[i] = led_create_simple(OBJECT(dev), GPIO_POLARITY_ACTIVE_HIGH, + LED_COLOR_GREEN, name); + g_free(name); + } } static const VMStateDescription mps2_scc_vmstate = { 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 config MPS2_SCC bool + select LED 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 read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" mps2_scc_write(uint64_t offset, uint64_t data, unsigned size) "MPS2 SCC write: 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) "MPS2 SCC config write: function %d device %d data 0x%" PRIx32 mps2_scc_cfg_read(unsigned function, unsigned device, uint32_t value) "MPS2 SCC config read: function %d device %d data 0x%" PRIx32 From patchwork Thu Sep 10 20:54:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 305643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD1D7C43461 for ; Thu, 10 Sep 2020 20:57:43 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4A03F2080A for ; Thu, 10 Sep 2020 20:57:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MwT0F4Zk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A03F2080A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amsat.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kGTdW-0001rR-Cc for qemu-devel@archiver.kernel.org; Thu, 10 Sep 2020 16:57:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kGTae-0004Mv-4N; Thu, 10 Sep 2020 16:54:44 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:39550) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kGTac-0000I4-ER; Thu, 10 Sep 2020 16:54:43 -0400 Received: by mail-wr1-x444.google.com with SMTP id a17so8650496wrn.6; Thu, 10 Sep 2020 13:54:41 -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=MwT0F4ZkItt59sl5P0p/1brApND5TzyvcuJOxWoG1vHwonqaKFLSRKqs6voVhxcasF 6mIWcvE8h8AIy2oPhmXI6JIkFeuC1ws0l38c05VmustMPfA282GXWDXPD2nOO1HMAidd UASReW9SSRUMGP0J/PbRcElHSi8pQ9vEKgt50rN/qTepWT8NAxIwLHHMFNnaglrl+E/g YLC9gFZea+zzrOd8qvr5EBN/QPS97wq9oMKqX3gufJOEwZcsP4n5rhmRacmz04dcMXbz z80xviK3eGRe2J93G9HQmbudw+S3R+eau7gmxiwGZY8f3NQ26CqEdohj8Ri1gNC9xUxh imdw== 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=YKcILOMPoftgfFYVuSvyPTS/d3EICEGtL4wJZ9Dm277UEFeA0L3xJs2mbkh1Sp///O 57dZbvGNIvO0CF0DGgUNk6yeVRStJuYO7RKEOPI0ooGDSNZ32IBAXFmjpNdSHbrAKEad ce3qyeREnZRRAYvcJrKi4LYzI0juHCG0Fc87WkR8Qo7b4i06Oy27Vg5rBED4NYrIO+dl AZeQYOixtdocZsT8TkIE16aWU9WxEVfqnv2H5H60vFIWU4xqfIJTxFrufV3ZPoy0AC7s 7iqnnef82zYqzXEHWH7KJ1ldSJEx6pyf9g/VOc1Dt3m0VN9apyv9K9A9JhjcBmfA2Wne F8gg== X-Gm-Message-State: AOAM532j9GyWdYKfz/zt4n34cv2kI0gUnvOEzyTfxU368rHn01n6nxAv eTbLQYl+6fwf+mJ190yFKqkBFb3lMWg= X-Google-Smtp-Source: ABdhPJz43sqO8iE6A8rNnWADbMBL/Ns5liM0btki4oJoBmddWIVTjYjFWVrjrMcAnTkBp7mqadFOEA== X-Received: by 2002:adf:bb44:: with SMTP id x4mr10814862wrg.76.1599771280425; Thu, 10 Sep 2020 13:54:40 -0700 (PDT) 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 t1sm5089317wmi.16.2020.09.10.13.54.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 13:54:39 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v5 7/7] hw/arm/tosa: Replace fprintf() calls by LED devices Date: Thu, 10 Sep 2020 22:54:29 +0200 Message-Id: <20200910205429.727766-8-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200910205429.727766-1-f4bug@amsat.org> References: <20200910205429.727766-1-f4bug@amsat.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::444; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Daniel_P=2E_Berran?= =?utf-8?b?Z8Op?= , Eduardo Habkost , Andrew Jeffery , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= , qemu-arm@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goate?= =?utf-8?q?r?= , Paolo Bonzini , Luc Michel , Joel Stanley Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é --- 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" #define TOSA_RAM 0x04000000 @@ -81,26 +82,6 @@ typedef struct TosaMiscGPIOState { SysBusDevice parent_obj; } TosaMiscGPIOState; -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 = DEVICE(obj); - qdev_init_gpio_in_named(dev, tosa_gpio_leds, "leds", 4); qdev_init_gpio_in_named(dev, tosa_reset, "reset", 1); } @@ -122,6 +102,7 @@ static void tosa_gpio_setup(PXA2xxState *cpu, TC6393xbState *tmio) { DeviceState *misc_gpio; + LEDState *led[4]; misc_gpio = sysbus_create_simple(TYPE_TOSA_MISC_GPIO, -1, NULL); @@ -143,14 +124,23 @@ static void tosa_gpio_setup(PXA2xxState *cpu, qdev_get_gpio_in(cpu->gpio, TOSA_GPIO_JC_CF_IRQ), NULL); + led[0] = led_create_simple(OBJECT(misc_gpio), GPIO_POLARITY_ACTIVE_HIGH, + LED_COLOR_BLUE, "bluetooth"); + led[1] = led_create_simple(OBJECT(misc_gpio), GPIO_POLARITY_ACTIVE_HIGH, + LED_COLOR_GREEN, "note"); + led[2] = led_create_simple(OBJECT(misc_gpio), GPIO_POLARITY_ACTIVE_HIGH, + LED_COLOR_AMBER, "charger-error"); + led[3] = led_create_simple(OBJECT(misc_gpio), GPIO_POLARITY_ACTIVE_HIGH, + 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)); qdev_connect_gpio_out(scp1, TOSA_GPIO_TC6393XB_L3V_ON, tc6393xb_l3v_get(tmio)); 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 config SPITZ bool